10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 54584Srh87107 * Common Development and Distribution License (the "License"). 64584Srh87107 * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*8275SEric Cheng * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #ifndef _SYS_EXACCT_H 270Sstevel@tonic-gate #define _SYS_EXACCT_H 280Sstevel@tonic-gate 290Sstevel@tonic-gate #include <sys/types.h> 300Sstevel@tonic-gate #include <sys/task.h> 310Sstevel@tonic-gate #include <sys/proc.h> 320Sstevel@tonic-gate #include <sys/procset.h> 330Sstevel@tonic-gate 340Sstevel@tonic-gate #ifdef _KERNEL 350Sstevel@tonic-gate #include <sys/acctctl.h> 360Sstevel@tonic-gate #include <sys/kmem.h> 370Sstevel@tonic-gate #include <sys/taskq.h> 380Sstevel@tonic-gate #include <sys/vnode.h> 390Sstevel@tonic-gate #endif 400Sstevel@tonic-gate 410Sstevel@tonic-gate #ifdef __cplusplus 420Sstevel@tonic-gate extern "C" { 430Sstevel@tonic-gate #endif 440Sstevel@tonic-gate 450Sstevel@tonic-gate #define EXACCT_VERSION 1 460Sstevel@tonic-gate 470Sstevel@tonic-gate /* 480Sstevel@tonic-gate * unpack and free allocation options: the behaviour of the ea_free_object() 490Sstevel@tonic-gate * function is coordinated with whether an unpack used EUP_ALLOC or EUP_NOALLOC, 500Sstevel@tonic-gate * such that unpacked object hierarchies can be later freed successfully. 510Sstevel@tonic-gate */ 520Sstevel@tonic-gate #define EUP_ALLOC 0x0 /* allocate new memory for vbl length objects */ 530Sstevel@tonic-gate #define EUP_NOALLOC 0x1 /* use existing buffer for vbl length objects */ 540Sstevel@tonic-gate #define EUP_ALLOC_MASK 0x1 550Sstevel@tonic-gate 560Sstevel@tonic-gate /* 570Sstevel@tonic-gate * wracct and putacct record type options: the properties of the partial and 580Sstevel@tonic-gate * interval records differ slightly: a partial record is a snapshot of the 590Sstevel@tonic-gate * resource usage for the given process or task, while an interval record 600Sstevel@tonic-gate * reports the current usage since the last interval record or creation. 610Sstevel@tonic-gate * Interval records are supported only for tasks. 620Sstevel@tonic-gate */ 630Sstevel@tonic-gate #define EW_PARTIAL (0x01) /* partial record */ 640Sstevel@tonic-gate #define EW_INTERVAL (0x02) /* interval record */ 650Sstevel@tonic-gate #define EW_FINAL (0x04) /* final record: used only in kernel */ 660Sstevel@tonic-gate 670Sstevel@tonic-gate /* 680Sstevel@tonic-gate * putacct contents option: the contents of the buffer passed to putacct may be 690Sstevel@tonic-gate * identified either as raw data or as a packed exacct record. 700Sstevel@tonic-gate */ 710Sstevel@tonic-gate #define EP_RAW 0 720Sstevel@tonic-gate #define EP_EXACCT_OBJECT 1 730Sstevel@tonic-gate 740Sstevel@tonic-gate #define EXACCT_MAX_BUFSIZE (64 * 1024) 750Sstevel@tonic-gate 760Sstevel@tonic-gate #ifndef _KERNEL 770Sstevel@tonic-gate extern size_t getacct(idtype_t, id_t, void *, size_t); 780Sstevel@tonic-gate extern int putacct(idtype_t, id_t, void *, size_t, int); 790Sstevel@tonic-gate extern int wracct(idtype_t, id_t, int); 800Sstevel@tonic-gate #endif /* ! _KERNEL */ 810Sstevel@tonic-gate 820Sstevel@tonic-gate /* 830Sstevel@tonic-gate * Error codes. libexacct reports these errors through the ea_error() function; 840Sstevel@tonic-gate * in the case of EXR_SYSCALL_FAIL, errno will contain the error code 850Sstevel@tonic-gate * encountered by the underlying system call. 860Sstevel@tonic-gate */ 870Sstevel@tonic-gate #define EXR_OK 0 880Sstevel@tonic-gate #define EXR_SYSCALL_FAIL 1 890Sstevel@tonic-gate #define EXR_CORRUPT_FILE 2 900Sstevel@tonic-gate #define EXR_EOF 3 910Sstevel@tonic-gate #define EXR_NO_CREATOR 4 920Sstevel@tonic-gate #define EXR_INVALID_BUF 5 930Sstevel@tonic-gate #define EXR_NOTSUPP 6 940Sstevel@tonic-gate #define EXR_UNKN_VERSION 7 950Sstevel@tonic-gate #define EXR_INVALID_OBJ 8 960Sstevel@tonic-gate 970Sstevel@tonic-gate typedef uint64_t ea_size_t; 980Sstevel@tonic-gate typedef uint32_t ea_catalog_t; 990Sstevel@tonic-gate 1000Sstevel@tonic-gate typedef enum {EO_ERROR = -1, EO_NONE = 0, EO_GROUP, EO_ITEM} ea_object_type_t; 1010Sstevel@tonic-gate 1020Sstevel@tonic-gate typedef struct ea_item { 1030Sstevel@tonic-gate /* 1040Sstevel@tonic-gate * The ei_u union is discriminated via the type field of the enclosing 1050Sstevel@tonic-gate * object's catalog tag. 1060Sstevel@tonic-gate */ 1070Sstevel@tonic-gate union { 1080Sstevel@tonic-gate uint8_t ei_u_uint8; 1090Sstevel@tonic-gate uint16_t ei_u_uint16; 1100Sstevel@tonic-gate uint32_t ei_u_uint32; 1110Sstevel@tonic-gate uint64_t ei_u_uint64; 1120Sstevel@tonic-gate double ei_u_double; 1130Sstevel@tonic-gate char *ei_u_string; 1140Sstevel@tonic-gate void *ei_u_object; /* for embedded packed object */ 1150Sstevel@tonic-gate void *ei_u_raw; 1160Sstevel@tonic-gate } ei_u; 1170Sstevel@tonic-gate ea_size_t ei_size; 1180Sstevel@tonic-gate } ea_item_t; 1190Sstevel@tonic-gate #define ei_uint8 ei_u.ei_u_uint8 1200Sstevel@tonic-gate #define ei_uint16 ei_u.ei_u_uint16 1210Sstevel@tonic-gate #define ei_uint32 ei_u.ei_u_uint32 1220Sstevel@tonic-gate #define ei_uint64 ei_u.ei_u_uint64 1230Sstevel@tonic-gate #define ei_double ei_u.ei_u_double 1240Sstevel@tonic-gate #define ei_string ei_u.ei_u_string 1250Sstevel@tonic-gate #define ei_object ei_u.ei_u_object 1260Sstevel@tonic-gate #define ei_raw ei_u.ei_u_raw 1270Sstevel@tonic-gate 1280Sstevel@tonic-gate typedef struct ea_group { 1290Sstevel@tonic-gate uint32_t eg_nobjs; 1300Sstevel@tonic-gate struct ea_object *eg_objs; 1310Sstevel@tonic-gate } ea_group_t; 1320Sstevel@tonic-gate 1330Sstevel@tonic-gate typedef struct ea_object { 1340Sstevel@tonic-gate ea_object_type_t eo_type; 1350Sstevel@tonic-gate union { 1360Sstevel@tonic-gate ea_group_t eo_u_group; 1370Sstevel@tonic-gate ea_item_t eo_u_item; 1380Sstevel@tonic-gate } eo_u; 1390Sstevel@tonic-gate struct ea_object *eo_next; 1400Sstevel@tonic-gate ea_catalog_t eo_catalog; 1410Sstevel@tonic-gate } ea_object_t; 1420Sstevel@tonic-gate #define eo_group eo_u.eo_u_group 1430Sstevel@tonic-gate #define eo_item eo_u.eo_u_item 1440Sstevel@tonic-gate 1450Sstevel@tonic-gate extern int ea_set_item(ea_object_t *, ea_catalog_t, const void *, size_t); 1460Sstevel@tonic-gate extern int ea_set_group(ea_object_t *, ea_catalog_t); 1470Sstevel@tonic-gate 1480Sstevel@tonic-gate /* 1490Sstevel@tonic-gate * In prior releases, the following three functions had the type void, and so 1500Sstevel@tonic-gate * could not return a status code. In SunOS 5.9, the return type has been 1510Sstevel@tonic-gate * changed to int, so that if errors are detected the invoking application 1520Sstevel@tonic-gate * can be notified appropriately. 1530Sstevel@tonic-gate */ 1540Sstevel@tonic-gate extern int ea_attach_to_object(ea_object_t *, ea_object_t *); 1550Sstevel@tonic-gate extern int ea_attach_to_group(ea_object_t *, ea_object_t *); 1560Sstevel@tonic-gate extern int ea_free_item(ea_object_t *, int); 1570Sstevel@tonic-gate 1580Sstevel@tonic-gate extern void ea_free_object(ea_object_t *, int); 1590Sstevel@tonic-gate extern size_t ea_pack_object(ea_object_t *, void *, size_t); 1600Sstevel@tonic-gate extern void *ea_alloc(size_t); 1610Sstevel@tonic-gate extern void ea_free(void *, size_t); 1620Sstevel@tonic-gate extern char *ea_strdup(const char *); 1630Sstevel@tonic-gate extern void ea_strfree(char *); 1640Sstevel@tonic-gate 1650Sstevel@tonic-gate #ifdef _KERNEL 1660Sstevel@tonic-gate extern ea_object_t *ea_alloc_item(ea_catalog_t, void *, size_t); 1670Sstevel@tonic-gate extern ea_object_t *ea_alloc_group(ea_catalog_t); 1680Sstevel@tonic-gate extern ea_object_t *ea_attach_item(ea_object_t *, void *, size_t, ea_catalog_t); 1690Sstevel@tonic-gate extern void exacct_commit_task(void *); 1700Sstevel@tonic-gate extern void exacct_commit_proc(proc_t *, int); 1714584Srh87107 extern void exacct_update_task_mstate(proc_t *); 1720Sstevel@tonic-gate extern int exacct_tag_task(ac_info_t *, task_t *, void *, size_t, int); 1730Sstevel@tonic-gate extern int exacct_tag_proc(ac_info_t *, pid_t, taskid_t, void *, size_t, int, 1740Sstevel@tonic-gate const char *); 1750Sstevel@tonic-gate extern void exacct_commit_flow(void *); 176*8275SEric Cheng extern int exacct_commit_netinfo(void *, int); 1770Sstevel@tonic-gate extern void exacct_init(void); 1780Sstevel@tonic-gate extern void *exacct_create_header(size_t *); 1790Sstevel@tonic-gate extern int exacct_write_header(ac_info_t *, void *, size_t); 1800Sstevel@tonic-gate extern void exacct_calculate_proc_usage(proc_t *, proc_usage_t *, 1810Sstevel@tonic-gate ulong_t *, int, int); 1820Sstevel@tonic-gate extern int exacct_commit_callback(ac_info_t *, void *, size_t, void *, 1830Sstevel@tonic-gate size_t, size_t *); 1840Sstevel@tonic-gate extern int exacct_assemble_proc_usage(ac_info_t *, proc_usage_t *, 1850Sstevel@tonic-gate int (*)(ac_info_t *, void *, size_t, void *, size_t, size_t *), 1860Sstevel@tonic-gate void *, size_t, size_t *, int); 1870Sstevel@tonic-gate extern int exacct_assemble_task_usage(ac_info_t *, task_t *, 1880Sstevel@tonic-gate int (*)(ac_info_t *, void *, size_t, void *, size_t, size_t *), 1890Sstevel@tonic-gate void *, size_t, size_t *, int); 1900Sstevel@tonic-gate extern int exacct_assemble_flow_usage(ac_info_t *, flow_usage_t *, 1910Sstevel@tonic-gate int (*)(ac_info_t *, void *, size_t, void *, size_t, size_t *), 1920Sstevel@tonic-gate void *, size_t, size_t *); 1934584Srh87107 extern void exacct_move_mstate(proc_t *, task_t *, task_t *); 194*8275SEric Cheng extern int exacct_assemble_net_usage(ac_info_t *, void *, 195*8275SEric Cheng int (*)(ac_info_t *, void *, size_t, void *, size_t, size_t *), 196*8275SEric Cheng void *, size_t, size_t *, int); 1970Sstevel@tonic-gate extern taskq_t *exacct_queue; 1980Sstevel@tonic-gate extern kmem_cache_t *exacct_object_cache; 1990Sstevel@tonic-gate #endif /* _KERNEL */ 2000Sstevel@tonic-gate 2010Sstevel@tonic-gate #ifdef __cplusplus 2020Sstevel@tonic-gate } 2030Sstevel@tonic-gate #endif 2040Sstevel@tonic-gate 2050Sstevel@tonic-gate #endif /* _SYS_EXACCT_H */ 206