1 Star 0 Fork 0

sktan/dbcache-openeuler20.03

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
hc.c 3.09 KB
一键复制 编辑 原始数据 按行查看 历史
#include <linux/backing-dev.h>
#include <linux/init.h>
#include <linux/kthread.h>
#include <linux/delay.h>
#include <linux/timer.h>
#include <linux/freezer.h>
#include <linux/sched/signal.h>
#include <linux/slab_def.h>
#include <linux/random.h>
#include "dbcache.h"
#include "hc.h"
#include "kmeans.h"
#include "util_db.h"
/**
* 左闭右闭区间:[hotness_ext_start, hotness_ext_end]
*/
void hotness_ext(struct bio *bio, unsigned int *hotness_ext_start, unsigned int *hotness_ext_end) {
sector_t sec_start;
sector_t sec_count;
sector_t sec_end;
sec_start = bio->bi_iter.bi_sector;
sec_count = bio_sectors(bio);
sec_end = sec_start + sec_count - 1;
*hotness_ext_start = sec_start / HOT_SECS;
*hotness_ext_end = sec_end / HOT_SECS;
}
static int bch_hc_thread(void *arg) {
int err;
unsigned int wait_ms;
struct cached_dev *dc = arg;
struct dbcache_hc_kthread *hc_th = dc->hc->hc_thread;
wait_queue_head_t *wq = &dc->hc->hc_thread->hc_wait_queue_head;
wait_ms = hc_th->sleep_time;
set_freezable();
do {
wait_event_interruptible_timeout(*wq, kthread_should_stop() || freezing(current), msecs_to_jiffies(wait_ms));
// printk("calling func kmeans_cluster.\n");
err = kmeans_cluster(dc);
if (!err) dc->hc->centers_valid = 1;
} while (!kthread_should_stop());
return 0;
}
int bch_hc_thread_start(struct cached_dev *dc) {
FUNC_SHOUT();
struct dbcache_hc_kthread *hc_th;
int err = 0;
hc_th = kmalloc(sizeof(struct dbcache_hc_kthread), GFP_KERNEL);
if (!hc_th) {
err = -ENOMEM;
goto out;
}
hc_th->sleep_time = DEF_HC_THREAD_SLEEP_TIME;
init_waitqueue_head(&hc_th->hc_wait_queue_head);
hc_th->dbcache_hc_task = kthread_run(bch_hc_thread, dc, "dbcache_hc");
if (IS_ERR(hc_th->dbcache_hc_task)) {
err = PTR_ERR(hc_th->dbcache_hc_task);
kfree(hc_th);
}
dc->hc->hc_thread = hc_th;
out:
return err;
}
void bch_hc_thread_stop(struct cached_dev *dc) {
FUNC_SHOUT();
struct dbcache_hc_kthread *hc_th = dc->hc->hc_thread;
if (!hc_th)
return;
kthread_stop(hc_th->dbcache_hc_task);
kfree(hc_th);
dc->hc->hc_thread = NULL;
}
int hc_init(struct cached_dev *dc) {
struct hotness_cluster *hc;
__u64 i;
__u64 hotness_nr;
int ret;
hc = kmalloc(sizeof(struct hotness_cluster), GFP_KERNEL);
if (!hc)
goto err;
hotness_nr = bdev_sectors(dc->bdev) / HOT_SECS;
if (bdev_sectors(dc->bdev) % HOT_SECS)
hotness_nr++;
printk("%s: size of hotness_array is %llu.\n", __func__, hotness_nr);
hc->hotness_nr = hotness_nr;
hc->count = 0;
hc->hotness_array = kmalloc_array(hotness_nr, sizeof(hotness_t), GFP_KERNEL);
if (!hc->hotness_array)
goto err;
for (i = 0; i < hotness_nr; i++) {
hc->hotness_array[i] = 0;
}
for (i = 0; i < N_CLUSTER; i++) {
hc->centers[i] = 0;
}
hc->centers_valid = 0;
dc->hc = hc;
ret = 0;
out:
return ret;
err:
pr_info("error in func %s", __func__);
ret = -1;
goto out;
}
void hc_release(struct cached_dev *dc) {
printk("%s: here!\n", __func__);
kfree(dc->hc->hotness_array);
kfree(dc->hc);
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/tanshikai/dbcache-openeuler20.03.git
git@gitee.com:tanshikai/dbcache-openeuler20.03.git
tanshikai
dbcache-openeuler20.03
dbcache-openeuler20.03
master

搜索帮助

D67c1975 1850385 1daf7b77 1850385