static inline struct block_t *get_block(uint16_t block_index)
{
- // TODO: This represents the same 2048 value in three different ways:
- // 1 << 11, 0x7FF + 1, as well as V_BLOCK_SIZE.
uint16_t index = block_index - 1;
- int offset = index & 0x7FF;
- char *p = get_shared_memory(index >> 11);
+ int offset = index & (V_BLOCK_SIZE - 1);
+ char *p = get_shared_memory(index / V_BLOCK_SIZE);
- if (!p) {
- pr_err("[INVALID BLOCK] index:%d free:%d err:%d", block_index, g_free_q.count, g_err_count);
- dump_stack();
- WARN_ON(1);
- }
+ if (!p)
+ return NULL;
- return (struct block_t *)(p + (offset << 11));
+ return (struct block_t *)(p + (offset * V_BLOCK_SIZE));
}
static inline void queue_init(struct queue_t *q, const char *name, uint16_t capacity)
static ssize_t status_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
- // int thread_count = 0;
- // int i;
+ int thread_count = 0;
+ int i;
- // for (i = 0; i < MAX_THREAD; i++) {
- // if (g_threads[i].block > 0)
- // thread_count ++;
- // }
+ for (i = 0; i < g_max_thread_id; i++) {
+ if (get_thread_table(i) > 0)
+ thread_count ++;
+ }
- // return snprintf(buf, PAGE_SIZE,
- // "free(%d%%):%d/%d task_on:%d gc_free:%u error:%u tid_max:%d\n",
- // BLOCK_RATIO(g_free_q.count), g_free_q.count, (g_free_q.count + thread_count),
- // g_task_on, g_free_count, g_err_count, g_max_thread_id);
- return -ENOTSUPP; // TODO
+ return snprintf(buf, PAGE_SIZE,
+ "free(%d%%):%d/%d task_on:%d gc_free:%u error:%u tid_max:%d\n",
+ BLOCK_RATIO(g_free_q.count), g_free_q.count, (g_free_q.count + thread_count),
+ g_task_on, g_free_count, g_err_count, g_max_thread_id);
}
static DEVICE_ATTR_RO(status);
static ssize_t thread_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
- // return snprintf(buf, PAGE_SIZE, "[%d] block:%u\n", g_thread, g_threads[g_thread].block);
- return -ENOTSUPP; // TODO
+ return snprintf(buf, PAGE_SIZE, "[%d] block:%u\n", g_thread, get_thread_table(g_thread));
}
static DEVICE_ATTR_RW(thread);
static void __exit vlogger_exit(void)
{
int i;
+ struct thread_table_field *ptr = NULL;
+ struct hlist_node *tmp_iter = NULL;
+ int tmp_bkt;
// TODO: What about the task that is running in the background?
queue_deinit(&g_free_q);
- kfree(g_thread_table); // TODO: Free innards
+ hash_for_each_safe(g_thread_table->data, tmp_bkt, tmp_iter, ptr, next) {
+ kfree(ptr);
+ }
+ kfree(g_thread_table);
for (i = 0; i < DEVICE_COUNT; i++)
kfree(g_shm_ptr[i]);