lprocfs_status.c

来自「lustre 1.6.5 source code」· C语言 代码 · 共 1,933 行 · 第 1/5 页

C
1,933
字号
        if (client_stat->nid_brw_stats)                OBD_FREE(client_stat->nid_brw_stats, sizeof(struct brw_stats));        OBD_FREE(client_stat, sizeof(*client_stat));        return;}void lprocfs_free_per_client_stats(struct obd_device *obd){        struct nid_stat *stat;        ENTRY;        /* we need extra list - because hash_exit called to early */        while(!list_empty(&obd->obd_nid_stats)) {                stat = list_entry(obd->obd_nid_stats.next,                                  struct nid_stat, nid_list);                lprocfs_free_client_stats(stat, NULL);        }        EXIT;}struct lprocfs_stats *lprocfs_alloc_stats(unsigned int num,                                          enum lprocfs_stats_flags flags){        struct lprocfs_stats *stats;        struct lprocfs_percpu *percpu;        unsigned int percpusize;        unsigned int i;        unsigned int num_cpu;        if (num == 0)                return NULL;        if (flags & LPROCFS_STATS_FLAG_NOPERCPU)                num_cpu = 1;        else                num_cpu = num_possible_cpus();        OBD_ALLOC(stats, offsetof(typeof(*stats), ls_percpu[num_cpu]));        if (stats == NULL)                return NULL;        if (flags & LPROCFS_STATS_FLAG_NOPERCPU) {                stats->ls_flags = flags;                spin_lock_init(&stats->ls_lock);                /* Use this lock only if there are no percpu areas */        } else {                stats->ls_flags = 0;        }        percpusize = offsetof(typeof(*percpu), lp_cntr[num]);        if (num_cpu > 1)                percpusize = L1_CACHE_ALIGN(percpusize);        stats->ls_percpu_size = num_cpu * percpusize;        OBD_ALLOC(stats->ls_percpu[0], stats->ls_percpu_size);        if (stats->ls_percpu[0] == NULL) {                OBD_FREE(stats, offsetof(typeof(*stats),                                         ls_percpu[num_cpu]));                return NULL;        }        stats->ls_num = num;        for (i = 1; i < num_cpu; i++)                stats->ls_percpu[i] = (void *)(stats->ls_percpu[i - 1]) +                        percpusize;        return stats;}void lprocfs_free_stats(struct lprocfs_stats **statsh){        struct lprocfs_stats *stats = *statsh;        unsigned int num_cpu;                if (!stats || (stats->ls_num == 0))                return;        *statsh = NULL;        if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU)                num_cpu = 1;        else                num_cpu = num_possible_cpus();        OBD_FREE(stats->ls_percpu[0], stats->ls_percpu_size);        OBD_FREE(stats, offsetof(typeof(*stats), ls_percpu[num_cpu]));}void lprocfs_clear_stats(struct lprocfs_stats *stats){        struct lprocfs_counter *percpu_cntr;        int i, j;        unsigned int num_cpu;        num_cpu = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU);        for (i = 0; i < num_cpu; i++) {                for (j = 0; j < stats->ls_num; j++) {                        percpu_cntr = &(stats->ls_percpu[i])->lp_cntr[j];                        atomic_inc(&percpu_cntr->lc_cntl.la_entry);                        percpu_cntr->lc_count = 0;                        percpu_cntr->lc_sum = 0;                        percpu_cntr->lc_min = LC_MIN_INIT;                        percpu_cntr->lc_max = 0;                        percpu_cntr->lc_sumsquare = 0;                        atomic_inc(&percpu_cntr->lc_cntl.la_exit);                }        }        lprocfs_stats_unlock(stats);}static ssize_t lprocfs_stats_seq_write(struct file *file, const char *buf,                                       size_t len, loff_t *off){        struct seq_file *seq = file->private_data;        struct lprocfs_stats *stats = seq->private;        lprocfs_clear_stats(stats);        return len;}static void *lprocfs_stats_seq_start(struct seq_file *p, loff_t *pos){        struct lprocfs_stats *stats = p->private;        /* return 1st cpu location */        return (*pos >= stats->ls_num) ? NULL :                &(stats->ls_percpu[0]->lp_cntr[*pos]);}static void lprocfs_stats_seq_stop(struct seq_file *p, void *v){}static void *lprocfs_stats_seq_next(struct seq_file *p, void *v, loff_t *pos){        struct lprocfs_stats *stats = p->private;        ++*pos;        return (*pos >= stats->ls_num) ? NULL :                &(stats->ls_percpu[0]->lp_cntr[*pos]);}/* seq file export of one lprocfs counter */static int lprocfs_stats_seq_show(struct seq_file *p, void *v){       struct lprocfs_stats *stats = p->private;       struct lprocfs_counter  *cntr = v;       struct lprocfs_counter  t, ret = { .lc_min = LC_MIN_INIT };       int i, idx, rc = 0;       unsigned int num_cpu;       if (cntr == &(stats->ls_percpu[0])->lp_cntr[0]) {               struct timeval now;               do_gettimeofday(&now);               rc = seq_printf(p, "%-25s %lu.%lu secs.usecs\n",                               "snapshot_time", now.tv_sec, now.tv_usec);               if (rc < 0)                       return rc;       }       idx = cntr - &(stats->ls_percpu[0])->lp_cntr[0];       if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU)               num_cpu = 1;       else               num_cpu = num_possible_cpus();       for (i = 0; i < num_cpu; i++) {               struct lprocfs_counter *percpu_cntr =                       &(stats->ls_percpu[i])->lp_cntr[idx];               int centry;               do {                       centry = atomic_read(&percpu_cntr->lc_cntl.la_entry);                       t.lc_count = percpu_cntr->lc_count;                       t.lc_sum = percpu_cntr->lc_sum;                       t.lc_min = percpu_cntr->lc_min;                       t.lc_max = percpu_cntr->lc_max;                       t.lc_sumsquare = percpu_cntr->lc_sumsquare;               } while (centry != atomic_read(&percpu_cntr->lc_cntl.la_entry) &&                        centry != atomic_read(&percpu_cntr->lc_cntl.la_exit));               ret.lc_count += t.lc_count;               ret.lc_sum += t.lc_sum;               if (t.lc_min < ret.lc_min)                       ret.lc_min = t.lc_min;               if (t.lc_max > ret.lc_max)                       ret.lc_max = t.lc_max;               ret.lc_sumsquare += t.lc_sumsquare;       }       if (ret.lc_count == 0)               goto out;       rc = seq_printf(p, "%-25s "LPD64" samples [%s]", cntr->lc_name,                       ret.lc_count, cntr->lc_units);       if (rc < 0)               goto out;       if ((cntr->lc_config & LPROCFS_CNTR_AVGMINMAX) && (ret.lc_count > 0)) {               rc = seq_printf(p, " "LPD64" "LPD64" "LPD64,                               ret.lc_min, ret.lc_max, ret.lc_sum);               if (rc < 0)                       goto out;               if (cntr->lc_config & LPROCFS_CNTR_STDDEV)                       rc = seq_printf(p, " "LPD64, ret.lc_sumsquare);               if (rc < 0)                       goto out;       }       rc = seq_printf(p, "\n"); out:       return (rc < 0) ? rc : 0;}struct seq_operations lprocfs_stats_seq_sops = {        start: lprocfs_stats_seq_start,        stop:  lprocfs_stats_seq_stop,        next:  lprocfs_stats_seq_next,        show:  lprocfs_stats_seq_show,};static int lprocfs_stats_seq_open(struct inode *inode, struct file *file){        struct proc_dir_entry *dp = PDE(inode);        struct seq_file *seq;        int rc;        LPROCFS_ENTRY_AND_CHECK(dp);        rc = seq_open(file, &lprocfs_stats_seq_sops);        if (rc) {                LPROCFS_EXIT();                return rc;        }        seq = file->private_data;        seq->private = dp->data;        return 0;}struct file_operations lprocfs_stats_seq_fops = {        .owner   = THIS_MODULE,        .open    = lprocfs_stats_seq_open,        .read    = seq_read,        .write   = lprocfs_stats_seq_write,        .llseek  = seq_lseek,        .release = lprocfs_seq_release,};int lprocfs_register_stats(struct proc_dir_entry *root, const char *name,                           struct lprocfs_stats *stats){        struct proc_dir_entry *entry;        LASSERT(root != NULL);        entry = create_proc_entry(name, 0644, root);        if (entry == NULL)                return -ENOMEM;        entry->proc_fops = &lprocfs_stats_seq_fops;        entry->data = (void *)stats;        return 0;}void lprocfs_counter_init(struct lprocfs_stats *stats, int index,                          unsigned conf, const char *name, const char *units){        struct lprocfs_counter *c;        int i;        unsigned int num_cpu;        LASSERT(stats != NULL);        num_cpu = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU);        for (i = 0; i < num_cpu; i++) {                c = &(stats->ls_percpu[i]->lp_cntr[index]);                c->lc_config = conf;                c->lc_count = 0;                c->lc_sum = 0;                c->lc_min = LC_MIN_INIT;                c->lc_max = 0;                c->lc_name = name;                c->lc_units = units;        }        lprocfs_stats_unlock(stats);}EXPORT_SYMBOL(lprocfs_counter_init);#define LPROCFS_OBD_OP_INIT(base, stats, op)                               \do {                                                                       \        unsigned int coffset = base + OBD_COUNTER_OFFSET(op);              \        LASSERT(coffset < stats->ls_num);                                  \        lprocfs_counter_init(stats, coffset, 0, #op, "reqs");              \} while (0)void lprocfs_init_ops_stats(int num_private_stats, struct lprocfs_stats *stats){        LPROCFS_OBD_OP_INIT(num_private_stats, stats, iocontrol);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, get_info);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, set_info_async);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, attach);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, detach);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, setup);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, precleanup);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, cleanup);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, process_config);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, postrecov);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, add_conn);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, del_conn);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, connect);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, reconnect);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, disconnect);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, statfs);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, statfs_async);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, packmd);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, unpackmd);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, checkmd);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, preallocate);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, precreate);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, create);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, destroy);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, setattr);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, setattr_async);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, getattr);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, getattr_async);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, brw);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, brw_async);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, prep_async_page);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, queue_async_io);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, queue_group_io);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, trigger_group_io);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, set_async_flags);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, teardown_async_page);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, merge_lvb);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, adjust_kms);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, punch);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, sync);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, migrate);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, copy);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, iterate);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, preprw);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, commitrw);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, enqueue);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, match);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, change_cbdata);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, cancel);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, cancel_unused);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, join_lru);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, init_export);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, destroy_export);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, extent_calc);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, llog_init);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, llog_finish);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, pin);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, unpin);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, import_event);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, notify);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, health_check);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, quotacheck);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, quotactl);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, quota_adjust_qunit);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, ping);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, register_page_removal_cb);        LPROCFS_OBD_OP_INIT(num_private_stats,stats,unregister_page_removal_cb);        LPROCFS_OBD_OP_INIT(num_private_stats, stats, register_lock_cancel_cb);        LPROCFS_OBD_OP_INIT(num_private_stats, stats,unregister_lock_cancel_cb);}int lprocfs_alloc_obd_stats(struct obd_device *obd, unsigned num_private_stats){        struct lprocfs_stats *stats;        unsigned int num_stats;        int rc, i;        LASSERT(obd->obd_stats == NULL);        LASSERT(obd->obd_proc_entry != NULL);        LASSERT(obd->obd_cntr_base == 0);        num_stats = ((int)sizeof(*obd->obd_type->typ_ops) / sizeof(void *)) +                num_private_stats - 1 /* o_owner */;        stats = lprocfs_alloc_stats(num_stats, 0);        if (stats == NULL)                return -ENOMEM;        lprocfs_init_ops_stats(num_private_stats, stats);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?