diff options
author | Eugene V. Lyubimkin <jackyf.devel@gmail.com> | 2008-11-16 20:36:18 +0200 |
---|---|---|
committer | Daniel Lange <DLange@git.local> | 2016-04-11 13:00:23 +0200 |
commit | bcb965d78ae0b4599fe77a2d641b3ff035658fc9 (patch) | |
tree | 59066e7fa5473b02eefaea37ac015cfaea7cd7c6 /plpa-1.1/src/plpa_api_probe.c | |
parent | 2eabf3432b05b93ce4de9af283ae549d0f7c18c8 (diff) | |
parent | c74c38760df69bb87e93dff18cf91464e5d02f37 (diff) | |
download | debian_htop-bcb965d78ae0b4599fe77a2d641b3ff035658fc9.tar.gz debian_htop-bcb965d78ae0b4599fe77a2d641b3ff035658fc9.tar.bz2 debian_htop-bcb965d78ae0b4599fe77a2d641b3ff035658fc9.zip |
Imported Debian patch 0.8.1-1debian/0.8.1-1
Diffstat (limited to 'plpa-1.1/src/plpa_api_probe.c')
-rw-r--r-- | plpa-1.1/src/plpa_api_probe.c | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/plpa-1.1/src/plpa_api_probe.c b/plpa-1.1/src/plpa_api_probe.c new file mode 100644 index 0000000..5dc0c38 --- /dev/null +++ b/plpa-1.1/src/plpa_api_probe.c @@ -0,0 +1,90 @@ +/* -*- c -*- + * + * Copyright (c) 2004-2005 The Trustees of Indiana University. + * All rights reserved. + * Copyright (c) 2004-2005 The Regents of the University of California. + * All rights reserved. + * Copyright (c) 2007-2008 Cisco, Inc. All rights reserved. + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ + +#include "plpa_config.h" +#include "plpa.h" +#include "plpa_internal.h" + +#include <errno.h> +#include <sys/syscall.h> +#include <unistd.h> + +/* Cache, just to make things a little more efficient */ +static PLPA_NAME(api_type_t) cache = PLPA_NAME_CAPS(PROBE_UNSET); + +/* The len value we find - not in public header, but used by the lib */ +size_t PLPA_NAME(len) = 0; + +int PLPA_NAME(api_probe_init)(void) +{ + PLPA_NAME(cpu_set_t) mask; + int rc; + size_t len; + + for (len = sizeof(mask); len != 0; len >>= 1) { + rc = syscall(__NR_sched_getaffinity, 0, len, &mask); + if (rc >= 0) { + /* OK, kernel is happy with a get(). Validate w/ a set(). */ + /* Note that kernel may have told us the "proper" size */ + size_t tmp = (0 != rc) ? ((size_t) rc) : len; + /* Pass mask=NULL, expect errno==EFAULT if tmp was OK + as a length */ + rc = syscall(__NR_sched_setaffinity, 0, tmp, NULL); + if ((rc < 0) && (errno == EFAULT)) { + cache = PLPA_NAME_CAPS(PROBE_OK); + PLPA_NAME(len) = tmp; + rc = 0; + break; + } + } + if (errno == ENOSYS) { + break; /* No point in looping */ + } + } + + if (rc >= 0) { + /* OK */ + } else if (errno == ENOSYS) { + /* Kernel returns ENOSYS because there is no support for + processor affinity */ + cache = PLPA_NAME_CAPS(PROBE_NOT_SUPPORTED); + } else { + /* Unknown! */ + cache = PLPA_NAME_CAPS(PROBE_UNKNOWN); + } + + return 0; +} + + +int PLPA_NAME(api_probe)(PLPA_NAME(api_type_t) *api_type) +{ + int ret; + + /* Check to see that we're initialized */ + if (!PLPA_NAME(initialized)) { + if (0 != (ret = PLPA_NAME(init)())) { + return ret; + } + } + + /* Check for bozo arguments */ + if (NULL == api_type) { + return EINVAL; + } + + /* All done */ + *api_type = cache; + return 0; +} |