static struct queue g_free_q;
-static int g_max_thread_id;
-
static uint64_t g_start_time;
static uint64_t g_hwc_offset;
static int g_task_on;
-static uint32_t g_free_count;
static uint32_t g_err_count;
ptr->blk = 0;
// TODO: The userspace might very well be using this block right now.
mutex_unlock(&g_block_mutex);
- g_free_count++;
}
}
uint16_t blk;
struct zlogger_block *block;
- if (g_max_thread_id < tid)
- g_max_thread_id = tid;
-
mutex_lock(&g_block_mutex);
blk = get_thread_table(tid, is_stdout);
if (blk)
.owner = THIS_MODULE,
};
-static ssize_t status_show(struct device *dev,
- struct device_attribute *attr, char *buf)
-{
- int thread_count = 0;
- int i;
- int is_stdout;
-
- for (i = 0; i < g_max_thread_id; i++) {
- for (is_stdout = 0; is_stdout <= 1; ++is_stdout) {
- if (get_thread_table(i, is_stdout) > 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);
-}
-
-static DEVICE_ATTR_RO(status);
-
-static ssize_t time_show(struct device *dev,
- struct device_attribute *attr, char *buf)
-{
- return snprintf(buf, PAGE_SIZE,
- "%llu %llu %llu\n", g_start_time, ktime_get_ns(), g_hwc_offset);
-}
-
-static DEVICE_ATTR_RO(time);
-
-static uint16_t g_block = 1;
-
-static ssize_t block_store(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t count)
-{
- unsigned long value;
-
- if (kstrtoul(buf, 10, &value) < 0) {
- pr_err("Failed to get value");
- return -EINVAL;
- }
-
- if (value < 1 || value > ZLOGGER_BLOCK_COUNT)
- return -EINVAL;
-
- g_block = value;
-
- return count;
-}
-
-static ssize_t block_show(struct device *dev,
- struct device_attribute *attr, char *buf)
-{
- struct zlogger_block *block = get_block((uint16_t)g_block);
-
- if (!block)
- return snprintf(buf, PAGE_SIZE, "[%d] Invalid block\n", g_block);
-
- return snprintf(buf, PAGE_SIZE, "[%d] pid:%u tid:%u offset:%u %llu %llu\n",
- g_block, block->head.pid, block->head.tid, block->head.offset,
- ((struct zlogger_entry *)(block->data))->time, block->head.ts);
-}
-
-static DEVICE_ATTR_RW(block);
-
-static uint16_t g_thread = 1;
-static ssize_t thread_store(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t count)
-{
- long value;
-
- if (kstrtol(buf, 10, &value) < 0) {
- pr_err("Failed to get value");
- return -EINVAL;
- }
-
- if (value < 1 || value > g_max_thread_id)
- return -EINVAL;
-
- g_thread = value;
-
- return count;
-}
-
-static ssize_t thread_show(struct device *dev,
- struct device_attribute *attr, char *buf)
-{
- return snprintf(buf, PAGE_SIZE, "[%d] block: %u, stdout block: %u\n",
- g_thread, get_thread_table(g_thread, false), get_thread_table(g_thread, true));
-}
-
-static DEVICE_ATTR_RW(thread);
-
-static struct attribute *zlogger_attributes[] = {
- &dev_attr_status.attr,
- &dev_attr_time.attr,
- &dev_attr_block.attr,
- &dev_attr_thread.attr,
- NULL,
-};
-
-static const struct attribute_group zlogger_attr_group = {
- .attrs = zlogger_attributes,
-};
-
static int zlogger_init(void)
{
int i = 0;
goto out_free_zlog_task;
}
- r = sysfs_create_group(&zlogger_device.this_device->kobj, &zlogger_attr_group);
- if (unlikely(r)) {
- dev_err(zlogger_device.this_device, "failed to create sysfs nodes with (%d)\n", r);
- goto out_free_zlogger_device;
- }
-
g_init = 1;
pr_info("Init success\n");
struct hlist_node *tmp_iter = NULL;
int tmp_bkt;
- sysfs_remove_group(&zlogger_device.this_device->kobj, &zlogger_attr_group);
misc_deregister(&zlogger_device);
// TODO: What about the task that is running in the background?