Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 196c253 in mainline


Ignore:
Timestamp:
2012-03-02T15:53:49Z (10 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master
Children:
3113d47
Parents:
efb8d15
Message:

add support for private/instance data also for the other sysinfo generated content

Location:
kernel/generic
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/sysinfo/sysinfo.h

    refb8d15 r196c253  
    11/*
    22 * Copyright (c) 2006 Jakub Vana
     3 * Copyright (c) 2012 Martin Decky
    34 * All rights reserved.
    45 *
     
    5455struct sysinfo_item;
    5556
    56 /** Gerated numeric value function */
    57 typedef sysarg_t (*sysinfo_fn_val_t)(struct sysinfo_item *);
     57/** Generated numeric value function */
     58typedef sysarg_t (*sysinfo_fn_val_t)(struct sysinfo_item *, void *);
     59
     60/** Sysinfo generated numberic value data
     61 *
     62 */
     63typedef struct {
     64        sysinfo_fn_val_t fn;  /**< Generated value function */
     65        void *data;           /**< Private data */
     66} sysinfo_gen_val_data_t;
    5867
    5968/** Generated binary data function */
    60 typedef void *(*sysinfo_fn_data_t)(struct sysinfo_item *, size_t *, bool);
     69typedef void *(*sysinfo_fn_data_t)(struct sysinfo_item *, size_t *, bool,
     70    void *);
     71
     72/** Sysinfo generated binary data data
     73 *
     74 */
     75typedef struct {
     76        sysinfo_fn_data_t fn;  /**< Generated binary data function */
     77        void *data;            /**< Private data */
     78} sysinfo_gen_data_data_t;
    6179
    6280/** Sysinfo item binary data
     
    7290 */
    7391typedef union {
    74         sysarg_t val;               /**< Constant numberic value */
    75         sysinfo_data_t data;        /**< Constant binary data */
    76         sysinfo_fn_val_t fn_val;    /**< Generated numeric value function */
    77         sysinfo_fn_data_t fn_data;  /**< Generated binary data function */
     92        sysarg_t val;                      /**< Constant numberic value */
     93        sysinfo_data_t data;               /**< Constant binary data */
     94        sysinfo_gen_val_data_t gen_val;    /**< Generated numeric value function */
     95        sysinfo_gen_data_data_t gen_data;  /**< Generated binary data function */
    7896} sysinfo_item_val_t;
    7997
     
    103121        sysinfo_fn_subtree_t fn;  /**< Generated subtree function */
    104122        void *data;               /**< Private data */
    105 } sysinfo_fn_subtree_data_t;
     123} sysinfo_gen_subtree_data_t;
    106124
    107125/** Sysinfo subtree (union)
     
    109127 */
    110128typedef union {
    111         struct sysinfo_item *table;           /**< Fixed subtree (list of subitems) */
    112         sysinfo_fn_subtree_data_t generator;  /**< Generated subtree */
     129        struct sysinfo_item *table;            /**< Fixed subtree (list of subitems) */
     130        sysinfo_gen_subtree_data_t generator;  /**< Generated subtree */
    113131} sysinfo_subtree_t;
    114132
     
    131149extern void sysinfo_set_item_data(const char *, sysinfo_item_t **, void *,
    132150    size_t);
    133 extern void sysinfo_set_item_fn_val(const char *, sysinfo_item_t **,
    134     sysinfo_fn_val_t);
    135 extern void sysinfo_set_item_fn_data(const char *, sysinfo_item_t **,
    136     sysinfo_fn_data_t);
     151extern void sysinfo_set_item_gen_val(const char *, sysinfo_item_t **,
     152    sysinfo_fn_val_t, void *);
     153extern void sysinfo_set_item_gen_data(const char *, sysinfo_item_t **,
     154    sysinfo_fn_data_t, void *);
    137155extern void sysinfo_set_item_undefined(const char *, sysinfo_item_t **);
    138156
  • kernel/generic/src/sysinfo/stats.c

    refb8d15 r196c253  
    8383 *
    8484 * @param item Sysinfo item (unused).
     85 * @param data Unused.
    8586 *
    8687 * @return System uptime (in secords).
    8788 *
    8889 */
    89 static sysarg_t get_stats_uptime(struct sysinfo_item *item)
     90static sysarg_t get_stats_uptime(struct sysinfo_item *item, void *data)
    9091{
    9192        /* This doesn't have to be very accurate */
     
    9899 * @param size    Size of the returned data.
    99100 * @param dry_run Do not get the data, just calculate the size.
     101 * @param data    Unused.
    100102 *
    101103 * @return Data containing several stats_cpu_t structures.
     
    104106 */
    105107static void *get_stats_cpus(struct sysinfo_item *item, size_t *size,
    106     bool dry_run)
     108    bool dry_run, void *data)
    107109{
    108110        *size = sizeof(stats_cpu_t) * config.cpu_count;
     
    293295 * @param size    Size of the returned data.
    294296 * @param dry_run Do not get the data, just calculate the size.
     297 * @param data    Unused.
    295298 *
    296299 * @return Data containing several stats_task_t structures.
     
    299302 */
    300303static void *get_stats_tasks(struct sysinfo_item *item, size_t *size,
    301     bool dry_run)
     304    bool dry_run, void *data)
    302305{
    303306        /* Messing with task structures, avoid deadlock */
     
    398401 * @param size    Size of the returned data.
    399402 * @param dry_run Do not get the data, just calculate the size.
     403 * @param data    Unused.
    400404 *
    401405 * @return Data containing several stats_task_t structures.
     
    404408 */
    405409static void *get_stats_threads(struct sysinfo_item *item, size_t *size,
    406     bool dry_run)
     410    bool dry_run, void *data)
    407411{
    408412        /* Messing with threads structures, avoid deadlock */
     
    590594 * @param size    Size of the returned data.
    591595 * @param dry_run Do not get the data, just calculate the size.
     596 * @param data    Unused.
    592597 *
    593598 * @return Data containing several stats_exc_t structures.
     
    596601 */
    597602static void *get_stats_exceptions(struct sysinfo_item *item, size_t *size,
    598     bool dry_run)
     603    bool dry_run, void *data)
    599604{
    600605        *size = sizeof(stats_exc_t) * IVT_ITEMS;
     
    711716 * @param size    Size of the returned data.
    712717 * @param dry_run Do not get the data, just calculate the size.
     718 * @param data    Unused.
    713719 *
    714720 * @return Data containing stats_physmem_t.
     
    717723 */
    718724static void *get_stats_physmem(struct sysinfo_item *item, size_t *size,
    719     bool dry_run)
     725    bool dry_run, void *data)
    720726{
    721727        *size = sizeof(stats_physmem_t);
     
    741747 * @param size    Size of the returned data.
    742748 * @param dry_run Do not get the data, just calculate the size.
     749 * @param data    Unused.
    743750 *
    744751 * @return Data several load_t values.
     
    747754 */
    748755static void *get_stats_load(struct sysinfo_item *item, size_t *size,
    749     bool dry_run)
     756    bool dry_run, void *data)
    750757{
    751758        *size = sizeof(load_t) * LOAD_STEPS;
     
    816823        mutex_initialize(&load_lock, MUTEX_PASSIVE);
    817824       
    818         sysinfo_set_item_fn_val("system.uptime", NULL, get_stats_uptime);
    819         sysinfo_set_item_fn_data("system.cpus", NULL, get_stats_cpus);
    820         sysinfo_set_item_fn_data("system.physmem", NULL, get_stats_physmem);
    821         sysinfo_set_item_fn_data("system.load", NULL, get_stats_load);
    822         sysinfo_set_item_fn_data("system.tasks", NULL, get_stats_tasks);
    823         sysinfo_set_item_fn_data("system.threads", NULL, get_stats_threads);
    824         sysinfo_set_item_fn_data("system.exceptions", NULL, get_stats_exceptions);
     825        sysinfo_set_item_gen_val("system.uptime", NULL, get_stats_uptime, NULL);
     826        sysinfo_set_item_gen_data("system.cpus", NULL, get_stats_cpus, NULL);
     827        sysinfo_set_item_gen_data("system.physmem", NULL, get_stats_physmem, NULL);
     828        sysinfo_set_item_gen_data("system.load", NULL, get_stats_load, NULL);
     829        sysinfo_set_item_gen_data("system.tasks", NULL, get_stats_tasks, NULL);
     830        sysinfo_set_item_gen_data("system.threads", NULL, get_stats_threads, NULL);
     831        sysinfo_set_item_gen_data("system.exceptions", NULL, get_stats_exceptions, NULL);
    825832        sysinfo_set_subtree_fn("system.tasks", NULL, get_stats_task, NULL);
    826833        sysinfo_set_subtree_fn("system.threads", NULL, get_stats_thread, NULL);
  • kernel/generic/src/sysinfo/sysinfo.c

    refb8d15 r196c253  
    11/*
    22 * Copyright (c) 2006 Jakub Vana
     3 * Copyright (c) 2012 Martin Decky
    34 * All rights reserved.
    45 *
     
    358359 *             a new root item (NULL for global sysinfo root).
    359360 * @param fn   Numeric value generator function.
    360  *
    361  */
    362 void sysinfo_set_item_fn_val(const char *name, sysinfo_item_t **root,
    363     sysinfo_fn_val_t fn)
     361 * @param data Private data.
     362 *
     363 */
     364void sysinfo_set_item_gen_val(const char *name, sysinfo_item_t **root,
     365    sysinfo_fn_val_t fn, void *data)
    364366{
    365367        /* Protect sysinfo tree consistency */
     
    372374        if (item != NULL) {
    373375                item->val_type = SYSINFO_VAL_FUNCTION_VAL;
    374                 item->val.fn_val = fn;
     376                item->val.gen_val.fn = fn;
     377                item->val.gen_val.data = data;
    375378        }
    376379       
     
    389392 *             a new root item (NULL for global sysinfo root).
    390393 * @param fn   Binary data generator function.
    391  *
    392  */
    393 void sysinfo_set_item_fn_data(const char *name, sysinfo_item_t **root,
    394     sysinfo_fn_data_t fn)
     394 * @param data Private data.
     395 *
     396 */
     397void sysinfo_set_item_gen_data(const char *name, sysinfo_item_t **root,
     398    sysinfo_fn_data_t fn, void *data)
    395399{
    396400        /* Protect sysinfo tree consistency */
     
    403407        if (item != NULL) {
    404408                item->val_type = SYSINFO_VAL_FUNCTION_DATA;
    405                 item->val.fn_data = fn;
     409                item->val.gen_data.fn = fn;
     410                item->val.gen_data.data = data;
    406411        }
    407412       
     
    512517                        break;
    513518                case SYSINFO_VAL_FUNCTION_VAL:
    514                         val = cur->val.fn_val(cur);
     519                        val = cur->val.gen_val.fn(cur, cur->val.gen_val.data);
    515520                        printf(" -> %" PRIun" (%#" PRIxn ") [generated]\n", val,
    516521                            val);
     
    518523                case SYSINFO_VAL_FUNCTION_DATA:
    519524                        /* N.B.: No data was actually returned (only a dry run) */
    520                         (void) cur->val.fn_data(cur, &size, true);
     525                        (void) cur->val.gen_data.fn(cur, &size, true,
     526                            cur->val.gen_data.data);
    521527                        printf(" (%zu bytes) [generated]\n", size);
    522528                        break;
     
    604610                        break;
    605611                case SYSINFO_VAL_FUNCTION_VAL:
    606                         ret.val = item->val.fn_val(item);
     612                        ret.val = item->val.gen_val.fn(item, item->val.gen_val.data);
    607613                        break;
    608614                case SYSINFO_VAL_FUNCTION_DATA:
    609                         ret.data.data = item->val.fn_data(item, &ret.data.size,
    610                             dry_run);
     615                        ret.data.data = item->val.gen_data.fn(item, &ret.data.size,
     616                            dry_run, item->val.gen_data.data);
    611617                        break;
    612618                }
Note: See TracChangeset for help on using the changeset viewer.