|
|||
1. Resource Management in the Solaris Operating System 3. Using the C Interface to Extended Accounting 4. Using the Perl Interface to Extended Accounting Dynamic Resource Pool Constraints and Objectives Using libpool to Manipulate Pool Configurations Programming Issues Associated With Resource Pools 7. Design Considerations for Resource Management Applications in Solaris Zones |
Resource Pool Code ExamplesThis section contains code examples of the resource pools interface. Ascertain the Number of CPUs in the Resource Poolsysconf(3C) provides information about the number of CPUs on an entire system. The following example provides the granularity of ascertaining the number of CPUs that are defined in a particular application's pools pset. The key points for this example include the following:
pool_value_t *pvals[2] = {NULL}; /* pvals[] should be NULL terminated */ /* NOTE: Return value checking/error processing omitted */ /* in all examples for brevity */ conf_loc = pool_dynamic_location(); conf = pool_conf_alloc(); pool_conf_open(conf, conf_loc, PO_RDONLY); my_pool_name = pool_get_binding(getpid()); my_pool = pool_get_pool(conf, my_pool_name); pvals[0] = pool_value_alloc(); pvals2[2] = { NULL, NULL }; pool_value_set_name(pvals[0], "type"); pool_value_set_string(pvals[0], "pset"); reslist = pool_query_pool_resources(conf, my_pool, &nelem, pvals); pool_value_free(pvals[0]); pool_query_resource_components(conf, reslist[0], &nelem, NULL); printf("pool %s: %u cpu", my_pool_ name, nelem); pool_conf_close(conf); List All Resource PoolsThe following example lists all resource pools defined in an application's pools pset. The key points of the example include the following:
conf = pool_conf_alloc(); pool_conf_open(conf, pool_dynamic_location(), PO_RDONLY); pl = pool_query_pools(conf, &nelem, NULL); pval = pool_value_alloc(); for (i = 0; i < nelem; i++) { pool_get_property(conf, pool_to_elem(conf, pl[i]), "pool.name", pval); pool_value_get_string(pval, &fname); printf("%s\n", name); } pool_value_free(pval); free(pl); pool_conf_close(conf); Report Pool Statistics for a Given PoolThe following example reports statistics for the designated pool. The key points for the example include the following:
printf("pool %s\n:" pool_name); pool = pool_get_pool(conf, pool_name); rl = pool_query_pool_resources(conf, pool, &nelem, NULL); for (i = 0; i < nelem; i++) { pool_get_property(conf, pool_resource_to_elem(conf, rl[i]), "type", pval); pool_value_get_string(pval, &type); type = strdup(type); snprintf(prop_name, 32, "%s.%s", type, "name"); pool_get_property(conf, pool_resource_to_elem(conf, rl[i]), prop_name, pval); pool_value_get_string(val, &res_name); res_name = strdup(res_name); snprintf(prop_name, 32, "%s.%s", type, "load"); pool_get_property(conf, pool_resource_to_elem(conf, rl[i]), prop_name, pval); pool_value_get_uint64(val, &load); snprintf(prop_name, 32, "%s.%s", type, "size"); pool_get_property(conf, pool_resource_to_elem(conf, rl[i]), prop_name, pval); pool_value_get_uint64(val, &size); printf("resource %s: size %llu load %llu\n", res_name, size, load); free(type); free(res_name); } free(rl); Set pool.comment Property and Add New PropertyThe following example sets the pool.comment property for the pset. The example also creates a new property in pool.newprop. The key point for the example includes the following:
pool_set_comment(const char *pool_name, const char *comment) { pool_t *pool; pool_elem_t *pool_elem; pool_value_t *pval = pool_value_alloc(); pool_conf_t *conf = pool_conf_alloc(); /* NOTE: need to be root to use PO_RDWR on static configuration file */ pool_conf_open(conf, pool_static_location(), PO_RDWR); pool = pool_get_pool(conf, pool_name); pool_value_set_string(pval, comment); pool_elem = pool_to_elem(conf, pool); pool_put_property(conf, pool_elem, "pool.comment", pval); printf("pool %s: pool.comment set to %s\n:" pool_name, comment); /* Now, create a new property, customized to installation site */ pool_value_set_string(pval, "New String Property"); pool_put_property(conf, pool_elem, "pool.newprop", pval); pool_conf_commit(conf, 0); /* NOTE: use 0 to ensure only */ /* static file gets updated */ pool_value_free(pval); pool_conf_close(conf); pool_conf_free(conf); /* NOTE: Use "pooladm -c" later, or pool_conf_commit(conf, 1) */ /* above for changes to the running system */ } An alternative way of modifying a pool's comment and adding a new pool property is to use poolcfg(1M). poolcfg -c 'modify pool pool-name (string pool.comment = "cmt-string")' poolcfg -c 'modify pool pool-name (string pool.newprop = "New String Property")' |
||
|