17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7eceb558Srh87107 * Common Development and Distribution License (the "License"). 6*7eceb558Srh87107 * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*7eceb558Srh87107 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #ifndef _SYS_EXACCT_H 277c478bd9Sstevel@tonic-gate #define _SYS_EXACCT_H 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate #include <sys/types.h> 327c478bd9Sstevel@tonic-gate #include <sys/task.h> 337c478bd9Sstevel@tonic-gate #include <sys/proc.h> 347c478bd9Sstevel@tonic-gate #include <sys/procset.h> 357c478bd9Sstevel@tonic-gate 367c478bd9Sstevel@tonic-gate #ifdef _KERNEL 377c478bd9Sstevel@tonic-gate #include <sys/acctctl.h> 387c478bd9Sstevel@tonic-gate #include <sys/kmem.h> 397c478bd9Sstevel@tonic-gate #include <sys/taskq.h> 407c478bd9Sstevel@tonic-gate #include <sys/vnode.h> 417c478bd9Sstevel@tonic-gate #endif 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate #ifdef __cplusplus 447c478bd9Sstevel@tonic-gate extern "C" { 457c478bd9Sstevel@tonic-gate #endif 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate #define EXACCT_VERSION 1 487c478bd9Sstevel@tonic-gate 497c478bd9Sstevel@tonic-gate /* 507c478bd9Sstevel@tonic-gate * unpack and free allocation options: the behaviour of the ea_free_object() 517c478bd9Sstevel@tonic-gate * function is coordinated with whether an unpack used EUP_ALLOC or EUP_NOALLOC, 527c478bd9Sstevel@tonic-gate * such that unpacked object hierarchies can be later freed successfully. 537c478bd9Sstevel@tonic-gate */ 547c478bd9Sstevel@tonic-gate #define EUP_ALLOC 0x0 /* allocate new memory for vbl length objects */ 557c478bd9Sstevel@tonic-gate #define EUP_NOALLOC 0x1 /* use existing buffer for vbl length objects */ 567c478bd9Sstevel@tonic-gate #define EUP_ALLOC_MASK 0x1 577c478bd9Sstevel@tonic-gate 587c478bd9Sstevel@tonic-gate /* 597c478bd9Sstevel@tonic-gate * wracct and putacct record type options: the properties of the partial and 607c478bd9Sstevel@tonic-gate * interval records differ slightly: a partial record is a snapshot of the 617c478bd9Sstevel@tonic-gate * resource usage for the given process or task, while an interval record 627c478bd9Sstevel@tonic-gate * reports the current usage since the last interval record or creation. 637c478bd9Sstevel@tonic-gate * Interval records are supported only for tasks. 647c478bd9Sstevel@tonic-gate */ 657c478bd9Sstevel@tonic-gate #define EW_PARTIAL (0x01) /* partial record */ 667c478bd9Sstevel@tonic-gate #define EW_INTERVAL (0x02) /* interval record */ 677c478bd9Sstevel@tonic-gate #define EW_FINAL (0x04) /* final record: used only in kernel */ 687c478bd9Sstevel@tonic-gate 697c478bd9Sstevel@tonic-gate /* 707c478bd9Sstevel@tonic-gate * putacct contents option: the contents of the buffer passed to putacct may be 717c478bd9Sstevel@tonic-gate * identified either as raw data or as a packed exacct record. 727c478bd9Sstevel@tonic-gate */ 737c478bd9Sstevel@tonic-gate #define EP_RAW 0 747c478bd9Sstevel@tonic-gate #define EP_EXACCT_OBJECT 1 757c478bd9Sstevel@tonic-gate 767c478bd9Sstevel@tonic-gate #define EXACCT_MAX_BUFSIZE (64 * 1024) 777c478bd9Sstevel@tonic-gate 787c478bd9Sstevel@tonic-gate #ifndef _KERNEL 797c478bd9Sstevel@tonic-gate extern size_t getacct(idtype_t, id_t, void *, size_t); 807c478bd9Sstevel@tonic-gate extern int putacct(idtype_t, id_t, void *, size_t, int); 817c478bd9Sstevel@tonic-gate extern int wracct(idtype_t, id_t, int); 827c478bd9Sstevel@tonic-gate #endif /* ! _KERNEL */ 837c478bd9Sstevel@tonic-gate 847c478bd9Sstevel@tonic-gate /* 857c478bd9Sstevel@tonic-gate * Error codes. libexacct reports these errors through the ea_error() function; 867c478bd9Sstevel@tonic-gate * in the case of EXR_SYSCALL_FAIL, errno will contain the error code 877c478bd9Sstevel@tonic-gate * encountered by the underlying system call. 887c478bd9Sstevel@tonic-gate */ 897c478bd9Sstevel@tonic-gate #define EXR_OK 0 907c478bd9Sstevel@tonic-gate #define EXR_SYSCALL_FAIL 1 917c478bd9Sstevel@tonic-gate #define EXR_CORRUPT_FILE 2 927c478bd9Sstevel@tonic-gate #define EXR_EOF 3 937c478bd9Sstevel@tonic-gate #define EXR_NO_CREATOR 4 947c478bd9Sstevel@tonic-gate #define EXR_INVALID_BUF 5 957c478bd9Sstevel@tonic-gate #define EXR_NOTSUPP 6 967c478bd9Sstevel@tonic-gate #define EXR_UNKN_VERSION 7 977c478bd9Sstevel@tonic-gate #define EXR_INVALID_OBJ 8 987c478bd9Sstevel@tonic-gate 997c478bd9Sstevel@tonic-gate typedef uint64_t ea_size_t; 1007c478bd9Sstevel@tonic-gate typedef uint32_t ea_catalog_t; 1017c478bd9Sstevel@tonic-gate 1027c478bd9Sstevel@tonic-gate typedef enum {EO_ERROR = -1, EO_NONE = 0, EO_GROUP, EO_ITEM} ea_object_type_t; 1037c478bd9Sstevel@tonic-gate 1047c478bd9Sstevel@tonic-gate typedef struct ea_item { 1057c478bd9Sstevel@tonic-gate /* 1067c478bd9Sstevel@tonic-gate * The ei_u union is discriminated via the type field of the enclosing 1077c478bd9Sstevel@tonic-gate * object's catalog tag. 1087c478bd9Sstevel@tonic-gate */ 1097c478bd9Sstevel@tonic-gate union { 1107c478bd9Sstevel@tonic-gate uint8_t ei_u_uint8; 1117c478bd9Sstevel@tonic-gate uint16_t ei_u_uint16; 1127c478bd9Sstevel@tonic-gate uint32_t ei_u_uint32; 1137c478bd9Sstevel@tonic-gate uint64_t ei_u_uint64; 1147c478bd9Sstevel@tonic-gate double ei_u_double; 1157c478bd9Sstevel@tonic-gate char *ei_u_string; 1167c478bd9Sstevel@tonic-gate void *ei_u_object; /* for embedded packed object */ 1177c478bd9Sstevel@tonic-gate void *ei_u_raw; 1187c478bd9Sstevel@tonic-gate } ei_u; 1197c478bd9Sstevel@tonic-gate ea_size_t ei_size; 1207c478bd9Sstevel@tonic-gate } ea_item_t; 1217c478bd9Sstevel@tonic-gate #define ei_uint8 ei_u.ei_u_uint8 1227c478bd9Sstevel@tonic-gate #define ei_uint16 ei_u.ei_u_uint16 1237c478bd9Sstevel@tonic-gate #define ei_uint32 ei_u.ei_u_uint32 1247c478bd9Sstevel@tonic-gate #define ei_uint64 ei_u.ei_u_uint64 1257c478bd9Sstevel@tonic-gate #define ei_double ei_u.ei_u_double 1267c478bd9Sstevel@tonic-gate #define ei_string ei_u.ei_u_string 1277c478bd9Sstevel@tonic-gate #define ei_object ei_u.ei_u_object 1287c478bd9Sstevel@tonic-gate #define ei_raw ei_u.ei_u_raw 1297c478bd9Sstevel@tonic-gate 1307c478bd9Sstevel@tonic-gate typedef struct ea_group { 1317c478bd9Sstevel@tonic-gate uint32_t eg_nobjs; 1327c478bd9Sstevel@tonic-gate struct ea_object *eg_objs; 1337c478bd9Sstevel@tonic-gate } ea_group_t; 1347c478bd9Sstevel@tonic-gate 1357c478bd9Sstevel@tonic-gate typedef struct ea_object { 1367c478bd9Sstevel@tonic-gate ea_object_type_t eo_type; 1377c478bd9Sstevel@tonic-gate union { 1387c478bd9Sstevel@tonic-gate ea_group_t eo_u_group; 1397c478bd9Sstevel@tonic-gate ea_item_t eo_u_item; 1407c478bd9Sstevel@tonic-gate } eo_u; 1417c478bd9Sstevel@tonic-gate struct ea_object *eo_next; 1427c478bd9Sstevel@tonic-gate ea_catalog_t eo_catalog; 1437c478bd9Sstevel@tonic-gate } ea_object_t; 1447c478bd9Sstevel@tonic-gate #define eo_group eo_u.eo_u_group 1457c478bd9Sstevel@tonic-gate #define eo_item eo_u.eo_u_item 1467c478bd9Sstevel@tonic-gate 1477c478bd9Sstevel@tonic-gate extern int ea_set_item(ea_object_t *, ea_catalog_t, const void *, size_t); 1487c478bd9Sstevel@tonic-gate extern int ea_set_group(ea_object_t *, ea_catalog_t); 1497c478bd9Sstevel@tonic-gate 1507c478bd9Sstevel@tonic-gate /* 1517c478bd9Sstevel@tonic-gate * In prior releases, the following three functions had the type void, and so 1527c478bd9Sstevel@tonic-gate * could not return a status code. In SunOS 5.9, the return type has been 1537c478bd9Sstevel@tonic-gate * changed to int, so that if errors are detected the invoking application 1547c478bd9Sstevel@tonic-gate * can be notified appropriately. 1557c478bd9Sstevel@tonic-gate */ 1567c478bd9Sstevel@tonic-gate extern int ea_attach_to_object(ea_object_t *, ea_object_t *); 1577c478bd9Sstevel@tonic-gate extern int ea_attach_to_group(ea_object_t *, ea_object_t *); 1587c478bd9Sstevel@tonic-gate extern int ea_free_item(ea_object_t *, int); 1597c478bd9Sstevel@tonic-gate 1607c478bd9Sstevel@tonic-gate extern void ea_free_object(ea_object_t *, int); 1617c478bd9Sstevel@tonic-gate extern size_t ea_pack_object(ea_object_t *, void *, size_t); 1627c478bd9Sstevel@tonic-gate extern void *ea_alloc(size_t); 1637c478bd9Sstevel@tonic-gate extern void ea_free(void *, size_t); 1647c478bd9Sstevel@tonic-gate extern char *ea_strdup(const char *); 1657c478bd9Sstevel@tonic-gate extern void ea_strfree(char *); 1667c478bd9Sstevel@tonic-gate 1677c478bd9Sstevel@tonic-gate #ifdef _KERNEL 1687c478bd9Sstevel@tonic-gate extern ea_object_t *ea_alloc_item(ea_catalog_t, void *, size_t); 1697c478bd9Sstevel@tonic-gate extern ea_object_t *ea_alloc_group(ea_catalog_t); 1707c478bd9Sstevel@tonic-gate extern ea_object_t *ea_attach_item(ea_object_t *, void *, size_t, ea_catalog_t); 1717c478bd9Sstevel@tonic-gate extern void exacct_commit_task(void *); 1727c478bd9Sstevel@tonic-gate extern void exacct_commit_proc(proc_t *, int); 173*7eceb558Srh87107 extern void exacct_update_task_mstate(proc_t *); 1747c478bd9Sstevel@tonic-gate extern int exacct_tag_task(ac_info_t *, task_t *, void *, size_t, int); 1757c478bd9Sstevel@tonic-gate extern int exacct_tag_proc(ac_info_t *, pid_t, taskid_t, void *, size_t, int, 1767c478bd9Sstevel@tonic-gate const char *); 1777c478bd9Sstevel@tonic-gate extern void exacct_commit_flow(void *); 1787c478bd9Sstevel@tonic-gate extern void exacct_init(void); 1797c478bd9Sstevel@tonic-gate extern void *exacct_create_header(size_t *); 1807c478bd9Sstevel@tonic-gate extern int exacct_write_header(ac_info_t *, void *, size_t); 1817c478bd9Sstevel@tonic-gate extern void exacct_calculate_proc_usage(proc_t *, proc_usage_t *, 1827c478bd9Sstevel@tonic-gate ulong_t *, int, int); 1837c478bd9Sstevel@tonic-gate extern int exacct_commit_callback(ac_info_t *, void *, size_t, void *, 1847c478bd9Sstevel@tonic-gate size_t, size_t *); 1857c478bd9Sstevel@tonic-gate extern int exacct_assemble_proc_usage(ac_info_t *, proc_usage_t *, 1867c478bd9Sstevel@tonic-gate int (*)(ac_info_t *, void *, size_t, void *, size_t, size_t *), 1877c478bd9Sstevel@tonic-gate void *, size_t, size_t *, int); 1887c478bd9Sstevel@tonic-gate extern int exacct_assemble_task_usage(ac_info_t *, task_t *, 1897c478bd9Sstevel@tonic-gate int (*)(ac_info_t *, void *, size_t, void *, size_t, size_t *), 1907c478bd9Sstevel@tonic-gate void *, size_t, size_t *, int); 1917c478bd9Sstevel@tonic-gate extern int exacct_assemble_flow_usage(ac_info_t *, flow_usage_t *, 1927c478bd9Sstevel@tonic-gate int (*)(ac_info_t *, void *, size_t, void *, size_t, size_t *), 1937c478bd9Sstevel@tonic-gate void *, size_t, size_t *); 194*7eceb558Srh87107 extern void exacct_move_mstate(proc_t *, task_t *, task_t *); 1957c478bd9Sstevel@tonic-gate extern taskq_t *exacct_queue; 1967c478bd9Sstevel@tonic-gate extern kmem_cache_t *exacct_object_cache; 1977c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 1987c478bd9Sstevel@tonic-gate 1997c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2007c478bd9Sstevel@tonic-gate } 2017c478bd9Sstevel@tonic-gate #endif 2027c478bd9Sstevel@tonic-gate 2037c478bd9Sstevel@tonic-gate #endif /* _SYS_EXACCT_H */ 204