Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

rk_util.h

Go to the documentation of this file.
00001 /*
00002  * rk_util.h
00003  *
00004  * Copyright (c) 2003, 2004 The University of Utah and the Flux Group.
00005  * All rights reserved.
00006  *
00007  * This file is licensed under the terms of the GNU Public License.  
00008  * See the file "license.terms" for restrictions on redistribution 
00009  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
00010  */
00011 
00012 /**
00013  * @file rk_util.h
00014  *
00015  * Header file for utility functions related to the TimeSys resource kernel.
00016  */
00017 
00018 #ifndef _rk_util_h
00019 #define _rk_util_h
00020 
00021 #ifdef __cplusplus
00022 extern "C" {
00023 #endif
00024 
00025 /*
00026  * Array element used to cache file descriptors for process' "stat" files.
00027  *
00028  * pid - The process ID or zero if this element is not allocated.
00029  * fd - The cached file descriptor for the process' "stat" file in "/proc".
00030  * cpu_usage - The total CPU usage for this process.
00031  */
00032 typedef struct rk_resource_set_proc {
00033     pid_t pid;
00034     int fd;
00035     unsigned long long cpu_usage;
00036 } *rk_resource_set_proc_t;
00037 
00038 /*
00039  * Array structure used to cache per-process data for processes in a resource
00040  * set.
00041  *
00042  * data - The array elements, sorted by pid in smallest to largest order.
00043  * Allocated elements are packed at the front of the array.
00044  * used - The number of elements in the array that are in use.
00045  * length - The number of elements in the array.
00046  */
00047 typedef struct rk_resource_set_proc_cache {
00048     rk_resource_set_proc_t data;
00049     size_t used;
00050     size_t length;
00051 } *rk_resource_set_proc_cache_t;
00052 
00053 /*
00054  * A structure used to hold the results of a rk_resource_set_get_usage call.
00055  *
00056  * proc_count - The number of processes in the resource set at the time of
00057  * sampling.
00058  * inactive_cpu_usage - The total CPU usage, in microseconds, for all of the
00059  * processes that were in the resource set but have since died.  Note:  This
00060  * value will only be set when a process cache is passed to
00061  * rk_resource_set_get_usage.
00062  * active_cpu_usage - The total CPU usage, in microseconds, for all of the
00063  * living processes in the resource set.
00064  */
00065 typedef struct rk_resource_set_usage {
00066     unsigned int proc_count;
00067     unsigned long long inactive_cpu_usage;
00068     unsigned long long active_cpu_usage;
00069 } *rk_resource_set_usage_t;
00070 
00071 /**
00072  * Search for a resource set by name and return the first one encountered.
00073  *
00074  * @param name The resource set name to search for.
00075  * @return A valid resource set pointer if the name was found, otherwise,
00076  * NULL_RESOURCE_SET.
00077  */
00078 rk_resource_set_t rk_resource_set_get_by_name(const char *name);
00079 
00080 /**
00081  * Compute the total resource usage for all the processes in a resource set.
00082  * Currently, this is implemented by stepping through all of the processes
00083  * attached to the resource set and pulling the usage information from
00084  * "/proc/<pid>/stat".  Unfortunately, the standard kernel does not provide
00085  * high-resolution data in the "stat" file, so the file in the "patch"
00086  * directory must be applied to the kernel before this function can be used.
00087  *
00088  * @sa rk_util/patch/tslinux-3.1-procstat.patch
00089  *
00090  * @param rs The resource set to compute the resource usage for.
00091  * @param rsu_inout An allocated rk_resource_set_stat_t object where the
00092  * results should be placed.
00093  * @param pc_inout The process cache object where data can be stored and reused
00094  * in future calls to this function.
00095  * @return Zero on success, otherwise, an errno value.
00096  */
00097 int rk_resource_set_get_usage(rk_resource_set_t rs,
00098                               rk_resource_set_usage_t rsu_inout,
00099                               rk_resource_set_proc_cache_t pc_inout);
00100 
00101 /**
00102  * Release any resources stored in the given process cache.
00103  *
00104  * @param pc The process cache whose contents should be released.
00105  */
00106 void rk_resource_set_proc_cache_release(rk_resource_set_proc_cache_t pc);
00107 
00108 #ifdef __cplusplus
00109 }
00110 #endif
00111     
00112 #endif

Generated on Fri Oct 22 07:50:24 2004 for CPU Broker by  doxygen 1.3.9.1