From owner-p4-projects@FreeBSD.ORG Sun Jan 30 17:50:33 2011 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id BE5381065679; Sun, 30 Jan 2011 17:50:32 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 81A641065672 for ; Sun, 30 Jan 2011 17:50:32 +0000 (UTC) (envelope-from trasz@freebsd.org) Received: from skunkworks.freebsd.org (skunkworks.freebsd.org [IPv6:2001:4f8:fff6::2d]) by mx1.freebsd.org (Postfix) with ESMTP id 6F67B8FC18 for ; Sun, 30 Jan 2011 17:50:32 +0000 (UTC) Received: from skunkworks.freebsd.org (localhost [127.0.0.1]) by skunkworks.freebsd.org (8.14.4/8.14.4) with ESMTP id p0UHoW6l078190 for ; Sun, 30 Jan 2011 17:50:32 GMT (envelope-from trasz@freebsd.org) Received: (from perforce@localhost) by skunkworks.freebsd.org (8.14.4/8.14.4/Submit) id p0UHoW1O078186 for perforce@freebsd.org; Sun, 30 Jan 2011 17:50:32 GMT (envelope-from trasz@freebsd.org) Date: Sun, 30 Jan 2011 17:50:32 GMT Message-Id: <201101301750.p0UHoW1O078186@skunkworks.freebsd.org> X-Authentication-Warning: skunkworks.freebsd.org: perforce set sender to trasz@freebsd.org using -f From: Edward Tomasz Napierala To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 188347 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 30 Jan 2011 17:50:33 -0000 http://p4web.freebsd.org/@@188347?ac=10 Change 188347 by trasz@trasz_victim on 2011/01/30 17:49:27 Use flag array instead of switch statements. Affected files ... .. //depot/projects/soc2009/trasz_limits/sys/kern/kern_container.c#70 edit .. //depot/projects/soc2009/trasz_limits/sys/sys/container.h#26 edit Differences ... ==== //depot/projects/soc2009/trasz_limits/sys/kern/kern_container.c#70 (text+ko) ==== @@ -88,129 +88,31 @@ SDT_PROBE_DEFINE2(container, kernel, container, join_failure, join-failure, "struct container *", "struct container *"); SDT_PROBE_DEFINE2(container, kernel, container, leave, leave, "struct container *", "struct container *"); -/* - * Amount stored in c_resources[] is thousand times bigger than what's - * visible to the userland. It gets fixed up when retrieving resource - * usage or adding rules. - */ -int -rusage_is_in_thousands(int resource) -{ - switch (resource) { - case RUSAGE_CPU: - case RUSAGE_WALLCLOCK: - case RUSAGE_PCTCPU: - return (1); - default: - return (0); - } -} - -/* - * Resource usage can drop, as opposed to only grow. - */ -static int -rusage_is_reclaimable(int resource) -{ - - switch (resource) { - case RUSAGE_CPU: - case RUSAGE_CORE: - case RUSAGE_WALLCLOCK: - return (0); - default: - return (1); - } -} - -/* - * Children inherit resource usage. - */ -static int -rusage_is_inheritable(int resource) -{ - - switch (resource) { - case RUSAGE_CPU: - case RUSAGE_CORE: - case RUSAGE_MEMLOCK: - case RUSAGE_NPROC: - case RUSAGE_SBSIZE: - case RUSAGE_NPTS: - case RUSAGE_SWAP: - case RUSAGE_NTHR: - case RUSAGE_NMSGQ: - case RUSAGE_MSGQQUEUED: - case RUSAGE_MSGQSIZE: - case RUSAGE_NSEM: - case RUSAGE_NSHM: - case RUSAGE_SHMSIZE: - case RUSAGE_WALLCLOCK: - case RUSAGE_PCTCPU: - return (0); - default: - return (1); - } -} - -/* - * rusage_{add,set}(9) can actually return an error and not update resource - * usage counters. Note that even when resource is not deniable, allocating - * resource might cause signals to be sent by RCTL code. - */ -static int -rusage_is_deniable(int resource) -{ - - switch (resource) { - case RUSAGE_RSS: - case RUSAGE_WALLCLOCK: - case RUSAGE_PCTCPU: - case RUSAGE_CPU: - return (0); - default: - return (1); - } -} - -/* - * Per-process resource usage information makes no sense, but per-credential - * one does. This kind of resources are usually allocated for process, but - * freed using credentials. - */ -int -rusage_is_sloppy(int resource) -{ - - switch (resource) { - case RUSAGE_SBSIZE: - case RUSAGE_NPTS: - case RUSAGE_SWAP: - case RUSAGE_NMSGQ: - case RUSAGE_MSGQQUEUED: - case RUSAGE_MSGQSIZE: - case RUSAGE_NSEM: - case RUSAGE_NSHM: - case RUSAGE_SHMSIZE: - return (1); - default: - return (0); - } -} - -/* - * XXX: Explain somehow. - */ -static int -rusage_is_dampened(int resource) -{ - switch (resource) { - case RUSAGE_PCTCPU: - return (1); - default: - return (0); - } -} +int rusage_types[] = { + [RUSAGE_CPU] = RUSAGE_IN_THOUSANDS, + [RUSAGE_FSIZE] = RUSAGE_RECLAIMABLE | RUSAGE_INHERITABLE | RUSAGE_DENIABLE, + [RUSAGE_DATA] = RUSAGE_RECLAIMABLE | RUSAGE_INHERITABLE | RUSAGE_DENIABLE, + [RUSAGE_STACK] = RUSAGE_RECLAIMABLE | RUSAGE_INHERITABLE | RUSAGE_DENIABLE, + [RUSAGE_CORE] = RUSAGE_DENIABLE, + [RUSAGE_RSS] = RUSAGE_RECLAIMABLE | RUSAGE_INHERITABLE, + [RUSAGE_MEMLOCK] = RUSAGE_RECLAIMABLE | RUSAGE_DENIABLE, + [RUSAGE_NPROC] = RUSAGE_RECLAIMABLE | RUSAGE_DENIABLE, + [RUSAGE_NOFILE] = RUSAGE_RECLAIMABLE | RUSAGE_INHERITABLE | RUSAGE_DENIABLE, + [RUSAGE_SBSIZE] = RUSAGE_RECLAIMABLE | RUSAGE_DENIABLE | RUSAGE_SLOPPY, + [RUSAGE_VMEM] = RUSAGE_RECLAIMABLE | RUSAGE_INHERITABLE | RUSAGE_DENIABLE, + [RUSAGE_NPTS] = RUSAGE_RECLAIMABLE | RUSAGE_DENIABLE | RUSAGE_SLOPPY, + [RUSAGE_SWAP] = RUSAGE_RECLAIMABLE | RUSAGE_DENIABLE | RUSAGE_SLOPPY, + [RUSAGE_NTHR] = RUSAGE_RECLAIMABLE | RUSAGE_DENIABLE, + [RUSAGE_MSGQQUEUED] = RUSAGE_RECLAIMABLE | RUSAGE_DENIABLE | RUSAGE_SLOPPY, + [RUSAGE_MSGQSIZE] = RUSAGE_RECLAIMABLE | RUSAGE_DENIABLE | RUSAGE_SLOPPY, + [RUSAGE_NMSGQ] = RUSAGE_RECLAIMABLE | RUSAGE_DENIABLE | RUSAGE_SLOPPY, + [RUSAGE_NSEM] = RUSAGE_RECLAIMABLE | RUSAGE_DENIABLE | RUSAGE_SLOPPY, + [RUSAGE_NSEMOP] = RUSAGE_RECLAIMABLE | RUSAGE_INHERITABLE | RUSAGE_DENIABLE, + [RUSAGE_NSHM] = RUSAGE_RECLAIMABLE | RUSAGE_DENIABLE | RUSAGE_SLOPPY, + [RUSAGE_SHMSIZE] = RUSAGE_RECLAIMABLE | RUSAGE_DENIABLE | RUSAGE_SLOPPY, + [RUSAGE_WALLCLOCK] = RUSAGE_IN_THOUSANDS, + [RUSAGE_PCTCPU] = RUSAGE_IN_THOUSANDS | RUSAGE_RECLAIMABLE | RUSAGE_DAMPENED, + [RUSAGE_SHMSIZE] = RUSAGE_RECLAIMABLE | RUSAGE_INHERITABLE | RUSAGE_DENIABLE }; static void container_add(struct container *dest, const struct container *src) ==== //depot/projects/soc2009/trasz_limits/sys/sys/container.h#26 (text+ko) ==== @@ -71,6 +71,54 @@ #define RUSAGE_MAX RUSAGE_PCTCPU /* + * Resource types. + */ +#define RUSAGE_IN_THOUSANDS 0x01 +#define RUSAGE_RECLAIMABLE 0x02 +#define RUSAGE_INHERITABLE 0x04 +#define RUSAGE_DENIABLE 0x08 +#define RUSAGE_SLOPPY 0x10 +#define RUSAGE_DAMPENED 0x20 + +extern int rusage_types[]; + +/* + * Amount stored in c_resources[] is thousand times bigger than what's + * visible to the userland. It gets fixed up when retrieving resource + * usage or adding rules. + */ +#define rusage_is_in_thousands(X) (rusage_types[X] & RUSAGE_IN_THOUSANDS) + +/* + * Resource usage can drop, as opposed to only grow. + */ +#define rusage_is_reclaimable(X) (rusage_types[X] & RUSAGE_RECLAIMABLE) + +/* + * Children inherit resource usage. + */ +#define rusage_is_inheritable(X) (rusage_types[X] & RUSAGE_INHERITABLE) + +/* + * rusage_{add,set}(9) can actually return an error and not update resource + * usage counters. Note that even when resource is not deniable, allocating + * resource might cause signals to be sent by RCTL code. + */ +#define rusage_is_deniable(X) (rusage_types[X] & RUSAGE_DENIABLE) + +/* + * Per-process resource usage information makes no sense, but per-credential + * one does. This kind of resources are usually allocated for process, but + * freed using credentials. + */ +#define rusage_is_sloppy(X) (rusage_types[X] & RUSAGE_SLOPPY) + +/* + * XXX: Explain somehow. + */ +#define rusage_is_dampened(X) (rusage_types[X] & RUSAGE_DAMPENED) + +/* * 'container' defines resource consumption for a particular * subject, such as process or jail. Containers form a graph - each * container has zero or more subcontainers and zero or more @@ -113,7 +161,4 @@ void container_proc_ucred_changed(struct proc *p, struct ucred *oldcred, struct ucred *newcred); -int rusage_is_in_thousands(int resource); -int rusage_is_sloppy(int resource); - #endif /* !_CONTAINER_H_ */