dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / rcap / rcapd / rcapd_collection_zone.c
blobdb86aa62767f0292394ce44a193a6c8f96960475
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
28 #include <procfs.h>
29 #include <project.h>
30 #include <stdlib.h>
31 #include <strings.h>
32 #include <zone.h>
33 #include <libzonecfg.h>
34 #include "rcapd.h"
35 #include "utils.h"
37 extern boolean_t gz_capped;
39 /* round up to next y = 2^n */
40 #define ROUNDUP(x, y) (((x) + ((y) - 1)) & ~((y) - 1))
42 static void
43 update_zone(zone_entry_t *zent, void *walk_data)
45 void(*update_notification_cb)(char *, char *, int, uint64_t, int) =
46 (void(*)(char *, char *, int, uint64_t, int))walk_data;
47 int changes;
48 int64_t max_rss;
49 uint64_t mcap;
50 lcollection_t *lcol;
51 rcid_t colid;
53 if (zone_getattr(zent->zid, ZONE_ATTR_PHYS_MCAP, &mcap,
54 sizeof (mcap)) != -1 && mcap != 0)
55 max_rss = ROUNDUP(mcap, 1024) / 1024;
56 else
57 max_rss = 0;
59 if (zent->zid == GLOBAL_ZONEID) {
60 if (max_rss > 0)
61 gz_capped = B_TRUE;
62 else
63 gz_capped = B_FALSE;
67 colid.rcid_type = RCIDT_ZONE;
68 colid.rcid_val = zent->zid;
70 lcol = lcollection_insert_update(&colid, max_rss, zent->zname,
71 &changes);
72 if (update_notification_cb != NULL)
73 update_notification_cb("zone", zent->zname, changes, max_rss,
74 (lcol != NULL) ? lcol->lcol_mark : 0);
78 /* ARGSUSED */
79 void
80 lcollection_update_zone(lcollection_update_type_t ut,
81 void(*update_notification_cb)(char *, char *, int, uint64_t, int))
83 int i;
84 uint_t nzents;
85 zone_entry_t *zents;
88 * Enumerate running zones.
90 if (get_running_zones(&nzents, &zents) != 0)
91 return;
93 for (i = 0; i < nzents; i++) {
94 update_zone(&zents[i], (void *)update_notification_cb);
98 free(zents);