mirror of https://github.com/F-Stack/f-stack.git
Tools/sysctl: make porting more general.
When porting tools, We should change the original codes as few as possible.
This commit is contained in:
parent
6e6fd87cff
commit
2d99e60c29
|
@ -435,7 +435,7 @@ ff_ioctl(int fd, unsigned long request, ...)
|
|||
va_start(ap, request);
|
||||
|
||||
argp = va_arg(ap, caddr_t);
|
||||
va_end(ap);
|
||||
va_end(ap);
|
||||
if ((rc = kern_ioctl(curthread, fd, req, argp)))
|
||||
goto kern_fail;
|
||||
|
||||
|
|
2
start.sh
2
start.sh
|
@ -60,7 +60,7 @@ do
|
|||
sleep 5
|
||||
else
|
||||
echo "${bin} ${conf} -c $cmask --proc-type=secondary --num-procs=${num_procs} --proc-id=${proc_id}"
|
||||
${bin} ${conf} -c $cmask --proc-type=secondary --num-procs=${num_procs} --proc-id=${proc_id} &
|
||||
${bin} ${conf} -c $cmask --proc-type=secondary --num-procs=${num_procs} --proc-id=${proc_id} &
|
||||
fi
|
||||
((proc_id++))
|
||||
fi
|
||||
|
|
|
@ -0,0 +1,162 @@
|
|||
/*
|
||||
* Copyright (C) 2017 THL A29 Limited, a Tencent company.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* Copied from FreeBSD's header files.
|
||||
*/
|
||||
|
||||
#ifndef _COMPAT_SYSCTL_H
|
||||
#define _COMPAT_SYSCTL_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
/*
|
||||
* Definitions for sysctl call. The sysctl call uses a hierarchical name
|
||||
* for objects that can be examined or modified. The name is expressed as
|
||||
* a sequence of integers. Like a file path name, the meaning of each
|
||||
* component depends on its place in the hierarchy. The top-level and kern
|
||||
* identifiers are defined here, and other identifiers are defined in the
|
||||
* respective subsystem header files.
|
||||
*/
|
||||
|
||||
#define CTL_MAXNAME 24 /* largest number of components supported */
|
||||
|
||||
#define CTLTYPE 0xf /* mask for the type */
|
||||
#define CTLTYPE_NODE 1 /* name is a node */
|
||||
#define CTLTYPE_INT 2 /* name describes an integer */
|
||||
#define CTLTYPE_STRING 3 /* name describes a string */
|
||||
#define CTLTYPE_S64 4 /* name describes a signed 64-bit number */
|
||||
#define CTLTYPE_OPAQUE 5 /* name describes a structure */
|
||||
#define CTLTYPE_STRUCT CTLTYPE_OPAQUE /* name describes a structure */
|
||||
#define CTLTYPE_UINT 6 /* name describes an unsigned integer */
|
||||
#define CTLTYPE_LONG 7 /* name describes a long */
|
||||
#define CTLTYPE_ULONG 8 /* name describes an unsigned long */
|
||||
#define CTLTYPE_U64 9 /* name describes an unsigned 64-bit number */
|
||||
#define CTLTYPE_U8 0xa /* name describes an unsigned 8-bit number */
|
||||
#define CTLTYPE_U16 0xb /* name describes an unsigned 16-bit number */
|
||||
#define CTLTYPE_S8 0xc /* name describes a signed 8-bit number */
|
||||
#define CTLTYPE_S16 0xd /* name describes a signed 16-bit number */
|
||||
#define CTLTYPE_S32 0xe /* name describes a signed 32-bit number */
|
||||
#define CTLTYPE_U32 0xf /* name describes an unsigned 32-bit number */
|
||||
|
||||
#define CTLFLAG_RD 0x80000000 /* Allow reads of variable */
|
||||
#define CTLFLAG_WR 0x40000000 /* Allow writes to the variable */
|
||||
#define CTLFLAG_RW (CTLFLAG_RD|CTLFLAG_WR)
|
||||
#define CTLFLAG_ANYBODY 0x10000000 /* All users can set this var */
|
||||
#define CTLFLAG_SECURE 0x08000000 /* Permit set only if securelevel<=0 */
|
||||
#define CTLFLAG_PRISON 0x04000000 /* Prisoned roots can fiddle */
|
||||
#define CTLFLAG_DYN 0x02000000 /* Dynamic oid - can be freed */
|
||||
#define CTLFLAG_SKIP 0x01000000 /* Skip this sysctl when listing */
|
||||
#define CTLMASK_SECURE 0x00F00000 /* Secure level */
|
||||
#define CTLFLAG_TUN 0x00080000 /* Default value is loaded from getenv() */
|
||||
#define CTLFLAG_RDTUN (CTLFLAG_RD|CTLFLAG_TUN)
|
||||
#define CTLFLAG_RWTUN (CTLFLAG_RW|CTLFLAG_TUN)
|
||||
#define CTLFLAG_MPSAFE 0x00040000 /* Handler is MP safe */
|
||||
#define CTLFLAG_VNET 0x00020000 /* Prisons with vnet can fiddle */
|
||||
#define CTLFLAG_DYING 0x00010000 /* Oid is being removed */
|
||||
#define CTLFLAG_CAPRD 0x00008000 /* Can be read in capability mode */
|
||||
#define CTLFLAG_CAPWR 0x00004000 /* Can be written in capability mode */
|
||||
#define CTLFLAG_STATS 0x00002000 /* Statistics, not a tuneable */
|
||||
#define CTLFLAG_NOFETCH 0x00001000 /* Don't fetch tunable from getenv() */
|
||||
#define CTLFLAG_CAPRW (CTLFLAG_CAPRD|CTLFLAG_CAPWR)
|
||||
|
||||
struct clockinfo {
|
||||
int hz; /* clock frequency */
|
||||
int tick; /* micro-seconds per hz tick */
|
||||
int spare;
|
||||
int stathz; /* statistics clock frequency */
|
||||
int profhz; /* profiling clock frequency */
|
||||
};
|
||||
|
||||
struct loadavg {
|
||||
__uint32_t ldavg[3];
|
||||
long fscale;
|
||||
};
|
||||
|
||||
/* Structure extended to include extended attribute field in ACPI 3.0. */
|
||||
struct bios_smap_xattr {
|
||||
u_int64_t base;
|
||||
u_int64_t length;
|
||||
u_int32_t type;
|
||||
u_int32_t xattr;
|
||||
} __packed;
|
||||
|
||||
/* systemwide totals computed every five seconds */
|
||||
struct vmtotal {
|
||||
int16_t t_rq; /* length of the run queue */
|
||||
int16_t t_dw; /* jobs in ``disk wait'' (neg priority) */
|
||||
int16_t t_pw; /* jobs in page wait */
|
||||
int16_t t_sl; /* jobs sleeping in core */
|
||||
int16_t t_sw; /* swapped out runnable/short block jobs */
|
||||
int32_t t_vm; /* total virtual memory */
|
||||
int32_t t_avm; /* active virtual memory */
|
||||
int32_t t_rm; /* total real memory in use */
|
||||
int32_t t_arm; /* active real memory */
|
||||
int32_t t_vmshr; /* shared virtual memory */
|
||||
int32_t t_avmshr; /* active shared virtual memory */
|
||||
int32_t t_rmshr; /* shared real memory */
|
||||
int32_t t_armshr; /* active shared real memory */
|
||||
int32_t t_free; /* free memory pages */
|
||||
};
|
||||
|
||||
struct efi_md {
|
||||
uint32_t md_type;
|
||||
#define EFI_MD_TYPE_NULL 0
|
||||
#define EFI_MD_TYPE_CODE 1 /* Loader text. */
|
||||
#define EFI_MD_TYPE_DATA 2 /* Loader data. */
|
||||
#define EFI_MD_TYPE_BS_CODE 3 /* Boot services text. */
|
||||
#define EFI_MD_TYPE_BS_DATA 4 /* Boot services data. */
|
||||
#define EFI_MD_TYPE_RT_CODE 5 /* Runtime services text. */
|
||||
#define EFI_MD_TYPE_RT_DATA 6 /* Runtime services data. */
|
||||
#define EFI_MD_TYPE_FREE 7 /* Unused/free memory. */
|
||||
#define EFI_MD_TYPE_BAD 8 /* Bad memory */
|
||||
#define EFI_MD_TYPE_RECLAIM 9 /* ACPI reclaimable memory. */
|
||||
#define EFI_MD_TYPE_FIRMWARE 10 /* ACPI NV memory */
|
||||
#define EFI_MD_TYPE_IOMEM 11 /* Memory-mapped I/O. */
|
||||
#define EFI_MD_TYPE_IOPORT 12 /* I/O port space. */
|
||||
#define EFI_MD_TYPE_PALCODE 13 /* PAL */
|
||||
uint32_t __pad;
|
||||
uint64_t md_phys;
|
||||
void *md_virt;
|
||||
uint64_t md_pages;
|
||||
uint64_t md_attr;
|
||||
#define EFI_MD_ATTR_UC 0x0000000000000001UL
|
||||
#define EFI_MD_ATTR_WC 0x0000000000000002UL
|
||||
#define EFI_MD_ATTR_WT 0x0000000000000004UL
|
||||
#define EFI_MD_ATTR_WB 0x0000000000000008UL
|
||||
#define EFI_MD_ATTR_UCE 0x0000000000000010UL
|
||||
#define EFI_MD_ATTR_WP 0x0000000000001000UL
|
||||
#define EFI_MD_ATTR_RP 0x0000000000002000UL
|
||||
#define EFI_MD_ATTR_XP 0x0000000000004000UL
|
||||
#define EFI_MD_ATTR_RT 0x8000000000000000UL
|
||||
};
|
||||
|
||||
struct efi_map_header {
|
||||
uint64_t memory_size;
|
||||
uint64_t descriptor_size;
|
||||
uint32_t descriptor_version;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -49,7 +49,7 @@ ff_ipc_init(void)
|
|||
char *dpdk_argv[] = {
|
||||
"-c1", "-n4",
|
||||
"--proc-type=secondary",
|
||||
"--log-level=0",
|
||||
"--log-level=3",
|
||||
};
|
||||
|
||||
int ret = rte_eal_init(sizeof(dpdk_argv)/sizeof(dpdk_argv[0]), dpdk_argv);
|
||||
|
@ -159,3 +159,106 @@ ff_ipc_recv(struct ff_msg **msg, uint16_t proc_id)
|
|||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
sysctl_ipc(uint16_t proc_id, int *name, unsigned namelen, void *old,
|
||||
size_t *oldlenp, const void *new, size_t newlen)
|
||||
{
|
||||
struct ff_msg *msg, *retmsg = NULL;
|
||||
|
||||
if (old != NULL && oldlenp == NULL) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
msg = ff_ipc_msg_alloc();
|
||||
if (msg == NULL) {
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
size_t oldlen = 0;
|
||||
if (oldlenp) {
|
||||
oldlen = *oldlenp;
|
||||
}
|
||||
|
||||
if (namelen + oldlen + newlen > msg->buf_len) {
|
||||
errno = EINVAL;
|
||||
ff_ipc_msg_free(msg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
char *buf_addr = msg->buf_addr;
|
||||
|
||||
msg->msg_type = FF_SYSCTL;
|
||||
msg->sysctl.name = (int *)buf_addr;
|
||||
msg->sysctl.namelen = namelen;
|
||||
memcpy(msg->sysctl.name, name, namelen*sizeof(int));
|
||||
|
||||
buf_addr += namelen*sizeof(int);
|
||||
|
||||
if (new != NULL && newlen != 0) {
|
||||
msg->sysctl.new = buf_addr;
|
||||
msg->sysctl.newlen = newlen;
|
||||
memcpy(msg->sysctl.new, new, newlen);
|
||||
|
||||
buf_addr += newlen;
|
||||
} else {
|
||||
msg->sysctl.new = NULL;
|
||||
msg->sysctl.newlen = 0;
|
||||
}
|
||||
|
||||
if (oldlenp != NULL) {
|
||||
msg->sysctl.oldlenp = (size_t *)buf_addr;
|
||||
memcpy(msg->sysctl.oldlenp, oldlenp, sizeof(size_t));
|
||||
buf_addr += sizeof(size_t);
|
||||
|
||||
if (old != NULL) {
|
||||
msg->sysctl.old = (void *)buf_addr;
|
||||
memcpy(msg->sysctl.old, old, *oldlenp);
|
||||
buf_addr += *oldlenp;
|
||||
} else {
|
||||
msg->sysctl.old = NULL;
|
||||
}
|
||||
} else {
|
||||
msg->sysctl.oldlenp = NULL;
|
||||
msg->sysctl.old = NULL;
|
||||
}
|
||||
|
||||
int ret = ff_ipc_send(msg, proc_id);
|
||||
if (ret < 0) {
|
||||
errno = EPIPE;
|
||||
ff_ipc_msg_free(msg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
do {
|
||||
if (retmsg != NULL) {
|
||||
ff_ipc_msg_free(retmsg);
|
||||
}
|
||||
ret = ff_ipc_recv(&retmsg, proc_id);
|
||||
if (ret < 0) {
|
||||
errno = EPIPE;
|
||||
ff_ipc_msg_free(msg);
|
||||
return -1;
|
||||
}
|
||||
} while (msg != retmsg);
|
||||
|
||||
if (retmsg->result == 0) {
|
||||
ret = 0;
|
||||
if (oldlenp && retmsg->sysctl.oldlenp) {
|
||||
*oldlenp = *retmsg->sysctl.oldlenp;
|
||||
}
|
||||
|
||||
if (old && retmsg->sysctl.old && oldlenp) {
|
||||
memcpy(old, retmsg->sysctl.old, *oldlenp);
|
||||
}
|
||||
} else {
|
||||
ret = -1;
|
||||
errno = retmsg->result;
|
||||
}
|
||||
|
||||
ff_ipc_msg_free(msg);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -35,4 +35,7 @@ int ff_ipc_msg_free(struct ff_msg *msg);
|
|||
int ff_ipc_send(const struct ff_msg *msg, uint16_t proc_id);
|
||||
int ff_ipc_recv(struct ff_msg **msg, uint16_t proc_id);
|
||||
|
||||
int sysctl_ipc(uint16_t proc_id, int *name, unsigned namelen, void *old,
|
||||
size_t *oldlenp, const void *new, size_t newlen);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -41,7 +41,8 @@ ifeq ($(FF_DPDK),)
|
|||
FF_DPDK=${TOPDIR}/dpdk/x86_64-native-linuxapp-gcc
|
||||
endif
|
||||
|
||||
FF_PROG_CFLAGS:= -g -Wall -Werror -DFSTACK
|
||||
FF_PROG_CFLAGS:= -g -Wall -Werror -DFSTACK -std=gnu99
|
||||
FF_PROG_CFLAGS+= -I${TOPDIR}/tools/compat
|
||||
FF_PROG_CFLAGS+= -I${TOPDIR}/lib -I${TOPDIR}/tools/ipc
|
||||
FF_PROG_CFLAGS+= -include ${FF_DPDK}/include/rte_config.h
|
||||
FF_PROG_CFLAGS+= -I${FF_DPDK}/include
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue