Phil Freund wrote:
I have started using resource pools to limit the number of CPUs available to a 
zone. I'm trying to find a way to track the pool assignment info and have the 
following questions:

Is there a command that will tell me which pools my zones are assigned to or do I have to 
check in each zone config for the value listed in the "pool=" parameter of the 
zone name?

Is there any pool related command that will tell me which resources, including 
zones, are assigned to each pool?

Although you can bind a zone to a pool, behind the scenes the system
does not really track a zone-to-pool binding.  This is managed at
the process level.  You can look at the zones to see what pools
they are assigned to but that information might not be correct
since the zone can be dynamically bound to a different pool using
poolbind(1M).

I have attached the source to a small program I wrote which prints
some resource management information about processes.  Most of
this is available via ps(1), but pool binding is not, so you might
find this useful.  You could trim the code down to only print the
pool binding for the 'init' process in each zone and that would give
you a good idea which pool the running zone is currently bound to.

We have talked about improving zone observability for stuff like this
but we haven't gotten that project off the ground yet.

Jerry
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/param.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <dirent.h>
#include <procfs.h>
#include <strings.h>
#include <pool.h>
#include <zone.h>
#include <project.h>

static void
pr_pid(boolean_t pactive)
{
	DIR *dirp;
	int procfd;
	dirent_t *dent;
	psinfo_t ps;
	struct project *pp, proj;
	char zname[ZONENAME_MAX];
	char procpath[MAXPATHLEN];
	char pname[32];
	char buf[1024];

	if ((dirp = opendir("/proc")) == NULL) {
		perror("can't open /proc");
		exit(1);
	}

	printf("%6s %6s %3s %12s %8s %12s %4s %s\n", "pid", "ppid",
	    "tsk", "project", "zone", "pool", "schd", "process");
	while ((dent = readdir(dirp)) != NULL) {
		if (dent->d_name[0] == '.')
			continue;

		(void) snprintf(procpath, sizeof (procpath), "/proc/%s/psinfo",
		    dent->d_name);

		if ((procfd = open(procpath, O_RDONLY)) == -1)
			continue;

		if (read(procfd, &ps, sizeof (ps)) == sizeof (psinfo_t)) {
			getzonenamebyid(ps.pr_zoneid, zname, sizeof (zname));
			pp = getprojbyid(ps.pr_projid, &proj, buf,
			    sizeof (buf));
			if (pp == NULL)
				snprintf(pname, sizeof (pname), "%d",
				    ps.pr_projid);
			else
				strlcpy(pname, pp->pj_name, sizeof (pname));
			printf("%6d %6d %3d %12s %8s %12s %4s %s\n",
			    ps.pr_pid, ps.pr_ppid,
			    ps.pr_taskid, pname,
			    zname,
			    (pactive ? pool_get_binding(ps.pr_pid) : ""),
			    ps.pr_lwp.pr_clname,
			    ps.pr_fname);
		}

		(void) close(procfd);
	}

	closedir(dirp);
}

main(int argc, char **argv)
{
	int status;
	boolean_t pactive = B_FALSE;

	if (pool_get_status(&status) == PO_SUCCESS && status == POOL_ENABLED)
		pactive = B_TRUE;

	pr_pid(pactive);
}
_______________________________________________
zones-discuss mailing list
zones-discuss@opensolaris.org

Reply via email to