1N/A/*
1N/A * CDDL HEADER START
1N/A *
1N/A * The contents of this file are subject to the terms of the
1N/A * Common Development and Distribution License (the "License").
1N/A * You may not use this file except in compliance with the License.
1N/A *
1N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
1N/A * or http://www.opensolaris.org/os/licensing.
1N/A * See the License for the specific language governing permissions
1N/A * and limitations under the License.
1N/A *
1N/A * When distributing Covered Code, include this CDDL HEADER in each
1N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1N/A * If applicable, add the following below this CDDL HEADER, with the
1N/A * fields enclosed by brackets "[]" replaced with your own identifying
1N/A * information: Portions Copyright [yyyy] [name of copyright owner]
1N/A *
1N/A * CDDL HEADER END
1N/A */
1N/A/*
1N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
1N/A * Use is subject to license terms.
1N/A */
1N/A
1N/A#ifndef _SYS_EXACCT_H
1N/A#define _SYS_EXACCT_H
1N/A
1N/A#include <sys/types.h>
1N/A#include <sys/task.h>
1N/A#include <sys/proc.h>
1N/A#include <sys/procset.h>
1N/A
1N/A#ifdef _KERNEL
1N/A#include <sys/acctctl.h>
1N/A#include <sys/kmem.h>
1N/A#include <sys/taskq.h>
1N/A#include <sys/vnode.h>
1N/A#endif
1N/A
1N/A#ifdef __cplusplus
1N/Aextern "C" {
1N/A#endif
1N/A
1N/A#define EXACCT_VERSION 1
1N/A
1N/A/*
1N/A * unpack and free allocation options: the behaviour of the ea_free_object()
1N/A * function is coordinated with whether an unpack used EUP_ALLOC or EUP_NOALLOC,
1N/A * such that unpacked object hierarchies can be later freed successfully.
1N/A */
1N/A#define EUP_ALLOC 0x0 /* allocate new memory for vbl length objects */
1N/A#define EUP_NOALLOC 0x1 /* use existing buffer for vbl length objects */
1N/A#define EUP_ALLOC_MASK 0x1
1N/A
1N/A/*
1N/A * wracct and putacct record type options: the properties of the partial and
1N/A * interval records differ slightly: a partial record is a snapshot of the
1N/A * resource usage for the given process or task, while an interval record
1N/A * reports the current usage since the last interval record or creation.
1N/A * Interval records are supported only for tasks.
1N/A */
1N/A#define EW_PARTIAL (0x01) /* partial record */
1N/A#define EW_INTERVAL (0x02) /* interval record */
1N/A#define EW_FINAL (0x04) /* final record: used only in kernel */
1N/A
1N/A/*
1N/A * putacct contents option: the contents of the buffer passed to putacct may be
1N/A * identified either as raw data or as a packed exacct record.
1N/A */
1N/A#define EP_RAW 0
1N/A#define EP_EXACCT_OBJECT 1
1N/A
1N/A#define EXACCT_MAX_BUFSIZE (64 * 1024)
1N/A
1N/A#ifndef _KERNEL
1N/Aextern size_t getacct(idtype_t, id_t, void *, size_t);
1N/Aextern int putacct(idtype_t, id_t, void *, size_t, int);
1N/Aextern int wracct(idtype_t, id_t, int);
1N/A#endif /* ! _KERNEL */
1N/A
1N/A/*
1N/A * Error codes. libexacct reports these errors through the ea_error() function;
1N/A * in the case of EXR_SYSCALL_FAIL, errno will contain the error code
1N/A * encountered by the underlying system call.
1N/A */
1N/A#define EXR_OK 0
1N/A#define EXR_SYSCALL_FAIL 1
1N/A#define EXR_CORRUPT_FILE 2
1N/A#define EXR_EOF 3
1N/A#define EXR_NO_CREATOR 4
1N/A#define EXR_INVALID_BUF 5
1N/A#define EXR_NOTSUPP 6
1N/A#define EXR_UNKN_VERSION 7
1N/A#define EXR_INVALID_OBJ 8
typedef uint64_t ea_size_t;
typedef uint32_t ea_catalog_t;
typedef enum {EO_ERROR = -1, EO_NONE = 0, EO_GROUP, EO_ITEM} ea_object_type_t;
typedef struct ea_item {
/*
* The ei_u union is discriminated via the type field of the enclosing
* object's catalog tag.
*/
union {
uint8_t ei_u_uint8;
uint16_t ei_u_uint16;
uint32_t ei_u_uint32;
uint64_t ei_u_uint64;
double ei_u_double;
char *ei_u_string;
void *ei_u_object; /* for embedded packed object */
void *ei_u_raw;
} ei_u;
ea_size_t ei_size;
} ea_item_t;
#define ei_uint8 ei_u.ei_u_uint8
#define ei_uint16 ei_u.ei_u_uint16
#define ei_uint32 ei_u.ei_u_uint32
#define ei_uint64 ei_u.ei_u_uint64
#define ei_double ei_u.ei_u_double
#define ei_string ei_u.ei_u_string
#define ei_object ei_u.ei_u_object
#define ei_raw ei_u.ei_u_raw
typedef struct ea_group {
uint32_t eg_nobjs;
struct ea_object *eg_objs;
} ea_group_t;
typedef struct ea_object {
ea_object_type_t eo_type;
union {
ea_group_t eo_u_group;
ea_item_t eo_u_item;
} eo_u;
struct ea_object *eo_next;
ea_catalog_t eo_catalog;
} ea_object_t;
#define eo_group eo_u.eo_u_group
#define eo_item eo_u.eo_u_item
extern int ea_set_item(ea_object_t *, ea_catalog_t, const void *, size_t);
extern int ea_set_group(ea_object_t *, ea_catalog_t);
/*
* In prior releases, the following three functions had the type void, and so
* could not return a status code. In SunOS 5.9, the return type has been
* changed to int, so that if errors are detected the invoking application
* can be notified appropriately.
*/
extern int ea_attach_to_object(ea_object_t *, ea_object_t *);
extern int ea_attach_to_group(ea_object_t *, ea_object_t *);
extern int ea_free_item(ea_object_t *, int);
extern void ea_free_object(ea_object_t *, int);
extern size_t ea_pack_object(ea_object_t *, void *, size_t);
extern void *ea_alloc(size_t);
extern void ea_free(void *, size_t);
extern char *ea_strdup(const char *);
extern void ea_strfree(char *);
#ifdef _KERNEL
extern ea_object_t *ea_alloc_item(ea_catalog_t, void *, size_t);
extern ea_object_t *ea_alloc_group(ea_catalog_t);
extern ea_object_t *ea_attach_item(ea_object_t *, void *, size_t, ea_catalog_t);
extern void exacct_commit_task(void *);
extern void exacct_commit_proc(proc_t *, int);
extern void exacct_update_task_mstate(proc_t *);
extern int exacct_tag_task(ac_info_t *, task_t *, void *, size_t, int);
extern int exacct_tag_proc(ac_info_t *, pid_t, taskid_t, void *, size_t, int,
const char *);
extern void exacct_commit_flow(void *);
extern int exacct_commit_netinfo(void *, int);
extern void exacct_init(void);
extern void *exacct_create_header(size_t *);
extern int exacct_write_header(ac_info_t *, void *, size_t);
extern void exacct_calculate_proc_usage(proc_t *, proc_usage_t *,
ulong_t *, int, int);
extern int exacct_commit_callback(ac_info_t *, void *, size_t, void *,
size_t, size_t *);
extern int exacct_assemble_proc_usage(ac_info_t *, proc_usage_t *,
int (*)(ac_info_t *, void *, size_t, void *, size_t, size_t *),
void *, size_t, size_t *, int);
extern int exacct_assemble_task_usage(ac_info_t *, task_t *,
int (*)(ac_info_t *, void *, size_t, void *, size_t, size_t *),
void *, size_t, size_t *, int);
extern int exacct_assemble_flow_usage(ac_info_t *, flow_usage_t *,
int (*)(ac_info_t *, void *, size_t, void *, size_t, size_t *),
void *, size_t, size_t *);
extern void exacct_move_mstate(proc_t *, task_t *, task_t *);
extern int exacct_assemble_net_usage(ac_info_t *, void *,
int (*)(ac_info_t *, void *, size_t, void *, size_t, size_t *),
void *, size_t, size_t *, int);
extern taskq_t *exacct_queue;
extern kmem_cache_t *exacct_object_cache;
#endif /* _KERNEL */
#ifdef __cplusplus
}
#endif
#endif /* _SYS_EXACCT_H */