summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sys/dev/acpi/uacpi.c13
-rw-r--r--sys/include/sys/sysctl.h5
-rw-r--r--sys/include/sys/workqueue.h21
-rw-r--r--sys/kern/kern_proc.c32
-rw-r--r--sys/kern/kern_spawn.c36
-rw-r--r--sys/kern/kern_sysctl.c6
-rw-r--r--sys/kern/kern_work.c31
-rw-r--r--usr.bin/sysctl/sysctl.c39
8 files changed, 134 insertions, 49 deletions
diff --git a/sys/dev/acpi/uacpi.c b/sys/dev/acpi/uacpi.c
index ffec436..6c2bf50 100644
--- a/sys/dev/acpi/uacpi.c
+++ b/sys/dev/acpi/uacpi.c
@@ -55,6 +55,9 @@
#include <vm/vm.h>
#include <string.h>
+#define pr_trace(fmt, ...) kprintf("acpi: " fmt, ##__VA_ARGS__)
+#define pr_error(...) pr_trace(__VA_ARGS__)
+
typedef struct {
uacpi_io_addr base;
uacpi_size length;
@@ -633,25 +636,25 @@ uacpi_init(void)
ret = uacpi_initialize(0);
if (uacpi_unlikely_error(ret)) {
- kprintf("uacpi init error: %s\n", uacpi_status_to_string(ret));
+ pr_error("uacpi init error: %s\n", uacpi_status_to_string(ret));
return -1;
}
ret = uacpi_namespace_load();
if (uacpi_unlikely_error(ret)) {
- kprintf("uacpi namespace load error: %s\n", uacpi_status_to_string(ret));
+ pr_error("uacpi namespace load error: %s\n", uacpi_status_to_string(ret));
return -1;
}
ret = uacpi_namespace_initialize();
if (uacpi_unlikely_error(ret)) {
- kprintf("uacpi namespace init error: %s\n", uacpi_status_to_string(ret));
+ pr_error("uacpi namespace init error: %s\n", uacpi_status_to_string(ret));
return -1;
}
ret = uacpi_finalize_gpe_initialization();
if (uacpi_unlikely_error(ret)) {
- kprintf("uacpi GPE init error: %s\n", uacpi_status_to_string(ret));
+ pr_error("uacpi GPE init error: %s\n", uacpi_status_to_string(ret));
return -1;
}
@@ -661,7 +664,7 @@ uacpi_init(void)
);
if (uacpi_unlikely_error(ret)) {
- kprintf("failed to install power button event: %s\n",
+ pr_error("failed to install power button event: %s\n",
uacpi_status_to_string(ret)
);
return -1;
diff --git a/sys/include/sys/sysctl.h b/sys/include/sys/sysctl.h
index 3b8d3c7..ce7510d 100644
--- a/sys/include/sys/sysctl.h
+++ b/sys/include/sys/sysctl.h
@@ -56,6 +56,11 @@
#define HW_MACHINE 7
/*
+ * List of 'proc.*' identifiers
+ */
+#define PROC_COUNT 8
+
+/*
* Option types (i.e., int, string, etc) for
* sysctl entries.
*
diff --git a/sys/include/sys/workqueue.h b/sys/include/sys/workqueue.h
index 478751d..9925f79 100644
--- a/sys/include/sys/workqueue.h
+++ b/sys/include/sys/workqueue.h
@@ -50,12 +50,18 @@ typedef void(*workfunc_t)(struct workqueue *wqp, struct work *wp);
* Represents work that may be added to a
* workqueue.
*
- * @name: Name of this work/task
- * @func: Function with work to be done
- * @cookie: Used for validating the work structure
+ * @name: Name of this work/task [i]
+ * @data: Optional data to be passed with work [p]
+ * @func: Function with work to be done [p]
+ * @cookie: Used for validating the work structure [i]
+ *
+ * Field attributes:
+ * - [i]: Used internally
+ * - [p]: Used as parameter
*/
struct work {
- const char *name;
+ char *name;
+ void *data;
workfunc_t func;
TAILQ_ENTRY(work) link;
};
@@ -81,16 +87,15 @@ struct workqueue {
size_t max_work;
ssize_t nwork;
uint16_t cookie;
- workfunc_t func;
struct proc *worktd;
struct mutex *lock;
};
-struct workqueue *workqueue_new(const char *name, workfunc_t func,
- size_t max_work, int ipl);
+struct workqueue *workqueue_new(const char *name, size_t max_work, int ipl);
-int workqueue_enq(struct workqueue *wqp, struct work *wp);
+int workqueue_enq(struct workqueue *wqp, const char *name, struct work *wp);
int workqueue_destroy(struct workqueue *wqp);
+int work_destroy(struct work *wp);
#endif /* !_KERNEL */
#endif /* !_SYS_WORKQUEUE_H_ */
diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c
index 87dcc74..8bc5680 100644
--- a/sys/kern/kern_proc.c
+++ b/sys/kern/kern_proc.c
@@ -29,14 +29,18 @@
#include <sys/types.h>
#include <sys/proc.h>
+#include <sys/errno.h>
#include <sys/cdefs.h>
#include <sys/vnode.h>
+#include <sys/tree.h>
#include <sys/syscall.h>
#include <sys/filedesc.h>
#include <sys/fcntl.h>
#include <string.h>
#include <crc32.h>
+extern volatile size_t g_nthreads;
+
pid_t
getpid(void)
{
@@ -50,7 +54,6 @@ getpid(void)
return td->pid;
}
-
pid_t
getppid(void)
{
@@ -100,6 +103,33 @@ proc_coredump(struct proc *td, uintptr_t fault_addr)
fd_close(fd);
}
+int
+proc_init(struct proc *td, struct proc *parent)
+{
+ struct mmap_lgdr *mlgdr;
+
+ mlgdr = dynalloc(sizeof(*mlgdr));
+ if (mlgdr == NULL) {
+ return -ENOMEM;
+ }
+
+ /* Add to parent leafq */
+ TAILQ_INSERT_TAIL(&parent->leafq, td, leaf_link);
+ atomic_inc_int(&parent->nleaves);
+ atomic_inc_64(&g_nthreads);
+ td->parent = parent;
+ td->exit_status = -1;
+ td->cred = parent->cred;
+
+ /* Initialize the mmap ledger */
+ mlgdr->nbytes = 0;
+ RBT_INIT(lgdr_entries, &mlgdr->hd);
+ td->mlgdr = mlgdr;
+ td->flags |= PROC_WAITED;
+ signals_init(td);
+ return 0;
+}
+
scret_t
sys_getpid(struct syscall_args *scargs)
{
diff --git a/sys/kern/kern_spawn.c b/sys/kern/kern_spawn.c
index b9551f3..7962ced 100644
--- a/sys/kern/kern_spawn.c
+++ b/sys/kern/kern_spawn.c
@@ -34,10 +34,8 @@
#include <sys/mman.h>
#include <sys/systm.h>
#include <sys/errno.h>
-#include <sys/atomic.h>
#include <sys/syslog.h>
#include <sys/syscall.h>
-#include <sys/atomic.h>
#include <sys/signal.h>
#include <sys/limits.h>
#include <sys/sched.h>
@@ -50,7 +48,6 @@
#define ARGVP_MAX (ARG_MAX / sizeof(void *))
static size_t next_pid = 1;
-extern volatile size_t g_nthreads;
/*
* TODO: envp
@@ -145,7 +142,6 @@ pid_t
spawn(struct proc *cur, void(*func)(void), void *p, int flags, struct proc **newprocp)
{
struct proc *newproc;
- struct mmap_lgdr *mlgdr;
int error;
pid_t pid;
@@ -156,19 +152,10 @@ spawn(struct proc *cur, void(*func)(void), void *p, int flags, struct proc **new
return -ENOMEM;
}
- mlgdr = dynalloc(sizeof(*mlgdr));
- if (mlgdr == NULL) {
- dynfree(newproc);
- try_free_data(p);
- pr_error("could not alloc proc mlgdr (-ENOMEM)\n");
- return -ENOMEM;
- }
-
memset(newproc, 0, sizeof(*newproc));
error = md_spawn(newproc, cur, (uintptr_t)func);
if (error < 0) {
dynfree(newproc);
- dynfree(mlgdr);
try_free_data(p);
pr_error("error initializing proc\n");
return error;
@@ -184,23 +171,16 @@ spawn(struct proc *cur, void(*func)(void), void *p, int flags, struct proc **new
cur->flags |= PROC_LEAFQ;
}
- /* Add to parent leafq */
- TAILQ_INSERT_TAIL(&cur->leafq, newproc, leaf_link);
- atomic_inc_int(&cur->nleaves);
- newproc->parent = cur;
- newproc->data = p;
- newproc->exit_status = -1;
- newproc->cred = cur->cred;
-
- /* Initialize the mmap ledger */
- mlgdr->nbytes = 0;
- RBT_INIT(lgdr_entries, &mlgdr->hd);
- newproc->mlgdr = mlgdr;
- newproc->flags |= PROC_WAITED;
+ error = proc_init(newproc, cur);
+ if (error < 0) {
+ dynfree(newproc);
+ try_free_data(p);
+ pr_error("error initializing proc\n");
+ return error;
+ }
- atomic_inc_64(&g_nthreads);
+ newproc->data = p;
newproc->pid = next_pid++;
- signals_init(newproc);
sched_enqueue_td(newproc);
pid = newproc->pid;
return pid;
diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c
index a4c16bb..1f5e578 100644
--- a/sys/kern/kern_sysctl.c
+++ b/sys/kern/kern_sysctl.c
@@ -40,6 +40,7 @@
HYRA_VERSION " " \
HYRA_BUILDDATE
+extern size_t g_nthreads;
static uint32_t pagesize = DEFAULT_PAGESIZE;
static char machine[] = HYRA_ARCH;
static char hyra[] = "Hyra";
@@ -62,7 +63,10 @@ static struct sysctl_entry common_optab[] = {
/* 'hw.*' */
[HW_PAGESIZE] = { HW_PAGESIZE, SYSCTL_OPTYPE_INT_RO, &pagesize },
[HW_NCPU] = { HW_NCPU, SYSCTL_OPTYPE_INT, NULL },
- [HW_MACHINE] = {HW_MACHINE, SYSCTL_OPTYPE_STR_RO, &machine }
+ [HW_MACHINE] = {HW_MACHINE, SYSCTL_OPTYPE_STR_RO, &machine },
+
+ /* 'proc.*' */
+ [PROC_COUNT] = { PROC_COUNT, SYSCTL_OPTYPE_INT_RO, &g_nthreads }
};
static int
diff --git a/sys/kern/kern_work.c b/sys/kern/kern_work.c
index f0eb68c..918af89 100644
--- a/sys/kern/kern_work.c
+++ b/sys/kern/kern_work.c
@@ -107,7 +107,6 @@ workqueue_worker(void)
* to hold queued up tasks.
*
* @name: Name to give the workqueue
- * @func: Function for work thread of this queue
* @max_work: Maximum number of jobs to be added
* @ipl: IPL that the work must operate in
*
@@ -115,7 +114,7 @@ workqueue_worker(void)
* otherwise a value of NULL is returned.
*/
struct workqueue *
-workqueue_new(const char *name, workfunc_t func, size_t max_work, int ipl)
+workqueue_new(const char *name, size_t max_work, int ipl)
{
struct workqueue *wqp;
struct proc *td;
@@ -138,7 +137,6 @@ workqueue_new(const char *name, workfunc_t func, size_t max_work, int ipl)
wqp->nwork = 0;
wqp->cookie = WQ_COOKIE;
wqp->lock = mutex_new(wqp->name);
- wqp->func = func;
/*
* We need to spawn the work thread which
@@ -162,23 +160,29 @@ workqueue_new(const char *name, workfunc_t func, size_t max_work, int ipl)
* workqueue.
*
* @wqp: Pointer to specific workqueue
+ * @name: Name to set for work unit
* @wp: Pointer to work that should be enqueued
*
* Returns zero on success, otherwise a less than
* zero value is returned.
*/
int
-workqueue_enq(struct workqueue *wqp, struct work *wp)
+workqueue_enq(struct workqueue *wqp, const char *name, struct work *wp)
{
if (wqp == NULL || wp == NULL) {
return -EINVAL;
}
+ if (name == NULL) {
+ return -EINVAL;
+ }
+
/* Verify that we have a valid workqueue */
if (__unlikely(wqp->cookie != WQ_COOKIE)) {
panic("workq: bad cookie on work enqueue\n");
}
+ wp->name = strdup(name);
mutex_acquire(wqp->lock, 0);
/*
@@ -249,3 +253,22 @@ workqueue_destroy(struct workqueue *wqp)
memset(wqp, 0, sizeof(*wqp));
return 0;
}
+
+/*
+ * Cleanup after work
+ *
+ * @wp: Work to clean up
+ */
+int
+work_destroy(struct work *wp)
+{
+ if (wp == NULL) {
+ return -EINVAL;
+ }
+
+ if (wp->name != NULL) {
+ dynfree(wp->name);
+ }
+
+ return 0;
+}
diff --git a/usr.bin/sysctl/sysctl.c b/usr.bin/sysctl/sysctl.c
index d4275a7..4a84484 100644
--- a/usr.bin/sysctl/sysctl.c
+++ b/usr.bin/sysctl/sysctl.c
@@ -46,13 +46,18 @@
#define NAME_NCPU "ncpu"
#define NAME_MACHINE "machine"
+/* Proc var string constants */
+#define NAME_COUNT "count"
+
/* Name start string constants */
#define NAME_KERN "kern"
#define NAME_HW "hw"
+#define NAME_PROC "proc"
/* Name start int constants */
#define NAME_DEF_KERN 0
#define NAME_DEF_HW 1
+#define NAME_DEF_PROC 2
/*
* Print the contents read from a sysctl
@@ -105,6 +110,12 @@ name_to_def(const char *name)
}
return -1;
+ case 'p':
+ if (strcmp(name, NAME_PROC) == 0) {
+ return NAME_DEF_PROC;
+ }
+
+ return -1;
}
return -1;
@@ -178,6 +189,28 @@ hw_node(const char *node, bool *is_str)
}
/*
+ * Handle parsing of 'proc.*' node names
+ *
+ * @node: Node name to parse
+ * @is_str: Set to true if string
+ */
+static int
+proc_node(const char *node, bool *is_str)
+{
+ switch (*node) {
+ case 'c':
+ if (strcmp(node, NAME_COUNT) == 0) {
+ *is_str = false;
+ return PROC_COUNT;
+ }
+
+ return -1;
+ }
+
+ return -1;
+}
+
+/*
* Convert string node to a sysctl name
* definition.
*
@@ -215,6 +248,8 @@ node_to_def(int name, const char *node, bool *is_str)
return kern_node(node, is_str);
case NAME_DEF_HW:
return hw_node(node, is_str);
+ case NAME_DEF_PROC:
+ return proc_node(node, is_str);
}
return -1;
@@ -240,12 +275,12 @@ main(int argc, char **argv)
p = strtok(var, ".");
if (p == NULL) {
- printf("sysctl: bad var\n");
+ printf("sysctl: bad var \"%s\"\n", p);
return -1;
}
if ((root = name_to_def(p)) < 0) {
- printf("sysctl: bad var \"%s\"", p);
+ printf("sysctl: bad var \"%s\"\n", p);
return root;
}