Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 154753 Details for
Bug 236962
[JAVA_BLOCKER] rtcheck on RHEL5 RT
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
rtcheck.c
rtcheck.c (text/x-csrc), 10.41 KB, created by
IBM Bug Proxy
on 2007-05-15 17:30:46 UTC
(
hide
)
Description:
rtcheck.c
Filename:
MIME Type:
Creator:
IBM Bug Proxy
Created:
2007-05-15 17:30:46 UTC
Size:
10.41 KB
patch
obsolete
>/* > * rt_check.c -- Check to see if the appropriate features are present > * for Real-Time Java to function correctly. > * > * Returns 0 on success, and non-zero on failure. The failure will indicate > * what necessary feature was not present > * > * This program is free software; you can redistribute it and/or modify > * it under the terms of the GNU General Public License as published by > * the Free Software Foundation; version 2 of the License. > * > * This program is distributed in the hope that it will be useful, > * but WITHOUT ANY WARRANTY; without even the implied warranty of > * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > * GNU General Public License for more details. > * > * You should have received a copy of the GNU General Public License > * along with this program; if not, write to the Free Software > * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. > * > * Copyright 2006 by IBM, All Rights Reserved > * > * Author(s): > * Theodore Ts'o > * Timothy R. Chavez <tinytim@us.ibm.com> > * > * Changelog: > * 05/03/2007 - Revamped for RHEL5-rt inclusion > * 05/08/2006 - Added verify_clockres to test whether or not clock > * resolution is within the acceptable range (<= 200us) for the JVM. > */ > >#include <time.h> >#include <dlfcn.h> >#include <errno.h> >#include <sched.h> >#include <stdio.h> >#include <stdint.h> >#include <stdlib.h> >#include <string.h> >#include <unistd.h> >#include <sys/time.h> >#include <sys/mman.h> >#include <sys/stat.h> >#include <sys/resource.h> > >#define FAIL_MEMLOCK 0x0001 >#define FAIL_SCHED 0x0002 >#define FAIL_ROBUST_MUTEX 0x0004 >#define FAIL_PREEMPT_RT 0x0008 >#define FAIL_HRTIMERS 0x0010 >#define FAIL_CLOCK_RES 0x0020 > >#define OPT_VERBOSE 0x0001 > >#define MAX_BUF_LEN 1024 >#define MAX_SYM_LEN 1024 >#define MAX_FILE_LEN 1024 > >#define FAIL_MSG "failed\n\t" >#define NEWLINE "\n" > >static void print_usage(char *progname) >{ > fprintf(stderr, "Usage: %s [-v]\n", progname); > exit(1); >} > >static int lookup_glibc_symbols(char *syms[], uint32_t flags) >{ > char *sym; > void *f; > int failed = 0; > > f = dlopen(NULL, RTLD_NOW); > > for (; (sym = *syms); syms++) { > if (flags & OPT_VERBOSE) > printf("\tchecking for %s: ", sym); > if (dlsym(f, sym)) { > if (flags & OPT_VERBOSE) > printf("found\n"); > } else { > if (flags & OPT_VERBOSE) > printf("not found\n"); > failed++; > } > } > > dlclose(f); > return failed; >} > >static int lookup_kernel_symbols(char *syms[], uint32_t flags) >{ > char *sym; > char c; > char addr[MAX_SYM_LEN]; > char ksym[MAX_SYM_LEN]; > int found = 0, failed = 0; > FILE *f; > > long mark = 0; > > if ((f = fopen("/proc/kallsyms", "r")) == NULL) { > if (flags & OPT_VERBOSE) > printf(FAIL_MSG > "kernel was not built with CONFIG_KALLSYMS=y\n"); > exit(1); > } > > /* > * FIXME: If /proc/kallsyms is missing, should we then check the System.map? > * The disadvantage here is that we'll have to make the assumption it > * is present in /boot or is named in some standard fashion. I think > * relying on /proc/kallsyms is sufficient and reasonable. > */ > > for (; (sym = *syms); syms++) { > if (flags & OPT_VERBOSE) > printf("\tchecking for %s: ", sym); > for (;;) { > if (fscanf(f, "%s %c %s", addr, &c, ksym) == EOF) { > if (mark) { > fseek(f, 0, SEEK_SET); > mark = 0; > } else { > if (flags & OPT_VERBOSE) > printf("not found\n"); > failed++; > break; > } > } else { > if ((found = !strcmp(sym, ksym))) { > if (flags & OPT_VERBOSE) > printf("found\n"); > mark = fseek(f, 0, SEEK_CUR); > break; > } > } > } > if (found) > fseek(f, mark, SEEK_SET); > else > fseek(f, 0, SEEK_SET); > } > > fclose(f); > return failed; >} > >/* Test 1: Memory lock > * > * Verify user ability to mlock ~32K of memory. > */ >#define BUF_LEN 32768 >static int verify_memlock(uint32_t flags) >{ > char *ptr; > int ret, page_size, len; > static char buf[BUF_LEN]; > struct rlimit rlim; > > if (flags & OPT_VERBOSE) > printf("Trying to lock memory: "); > > page_size = sysconf(_SC_PAGESIZE); > > /* > * Make sure the pointer is page aligned and the length is a multiple > * of a page size. Not strictly required by Linux, but some OS's may > * require this. > */ > ptr = (char *) ((unsigned long) buf & ~(page_size-1)); > len = (BUF_LEN - (buf - ptr)) & ~(page_size-1); > > if ((ret = mlock(ptr, len)) < 0) { > if (flags & OPT_VERBOSE) > printf(FAIL_MSG "mlock: %s\n", strerror(errno)); > return FAIL_MEMLOCK; > } > > if ((ret = munlock(ptr, len)) < 0) { > if (flags & OPT_VERBOSE) > printf(FAIL_MSG "munlock: %s\n", strerror(errno)); > return FAIL_MEMLOCK; > } > > if ((ret = getrlimit(RLIMIT_MEMLOCK, &rlim)) < 0) { > if (flags & OPT_VERBOSE) > printf(FAIL_MSG "getrlimit: %s\n", strerror(errno)); > return FAIL_MEMLOCK; > } > > if (rlim.rlim_cur != RLIM_INFINITY) { > if (flags & OPT_VERBOSE) > printf(FAIL_MSG "RLIMIT_MLOCK is %u\n", > (unsigned int) rlim.rlim_cur); > return FAIL_MEMLOCK; > } > > if (flags & OPT_VERBOSE) > printf("ok\n"); > > return ret; >} > >/* Test 2: Scheduler > * > * Verify user ability to run sched_setscheduler with SCHED_RR (SCHED_FIFO > * implicitly) via the PAM configuration. > */ >static int verify_sched(uint32_t flags) >{ > int ret, policy, new_policy; > struct sched_param param, new_param; > > if (flags & OPT_VERBOSE) > printf("Trying to request real-time scheduling: "); > > if ((ret = policy = sched_getscheduler(0)) < 0) { > perror("sched_getscheduler"); > return FAIL_SCHED; > } > > if ((ret = sched_getparam(0, ¶m)) < 0) { > perror("sched_getparam"); > return FAIL_SCHED; > } > > new_param = param; > new_policy = SCHED_RR; > new_param.sched_priority = sched_get_priority_max(new_policy); > > if ((ret = sched_setscheduler(0, new_policy, &new_param)) < 0) { > if (flags & OPT_VERBOSE) > printf(FAIL_MSG "sched_setscheduler: %s\n", > strerror(errno)); > return FAIL_SCHED; > } > > if ((ret = sched_setscheduler(0, policy, ¶m)) < 0) { > if (flags & OPT_VERBOSE) > printf(FAIL_MSG "resetting original scheduler: %s\n", > strerror(errno)); > return FAIL_SCHED; > } > > if (flags & OPT_VERBOSE) > printf("ok\n"); > > return ret; >} > >/* Test 3: CONFIG_PREEMPT_RT > * > * Verify that the kernel was compiled with CONFIG_PREEMPT_RT=y. If the file > * "/proc/loadavgrt" is present, we know that it was without having to muck w/ > * kernel configuration files or version numbers. This ultimately tells us the > * kernel was compiled with the out-of-tree RT extensions. > */ >static int verify_preempt_rt(uint32_t flags) >{ > struct stat buf; > > if (flags & OPT_VERBOSE) > printf("Checking for out-of-tree RT extensions: "); > > if (stat("/proc/loadavgrt", &buf)) { > if (flags & OPT_VERBOSE) > printf(FAIL_MSG > "kernel was not built with CONFIG_PREEMPT_RT=y\n"); > return FAIL_PREEMPT_RT; > } > > if (flags & OPT_VERBOSE) > printf("ok\n"); > > return 0; >} > >/* Test 4: Robust mutexes > * > * Verify that the following glibc symbols exist: > * o pthread_mutex_init > * o pthread_mutexattr_getprotocol > * o pthread_mutexattr_setprotocol > * > * Verify that the following kernel symbols exist: > * o __rt_mutex_init > * o __rt_mutex_adjust_prio > * > * The existence of these symbols implies robust mutex support in both > * the kernel and userspace. > */ >static int verify_robust_mutex(uint32_t flags) >{ > int ret, failed = 0; > static char *syms[] = { "pthread_mutex_init", /* placebo test */ > "pthread_mutexattr_getprotocol", > "pthread_mutexattr_setprotocol", > /* add other required symbols */ > 0 }; > static char *ksyms[] = { "__rt_mutex_init", > "__rt_mutex_adjust_prio", > /* add other required symbols */ > 0 }; > > if (flags & OPT_VERBOSE) > printf("Checking for robust (PI) mutex kernel support: "); > > if ((ret = lookup_kernel_symbols(ksyms, 0)) != 0) { > if (flags & OPT_VERBOSE) { > printf(NEWLINE); > lookup_kernel_symbols(ksyms, flags); > } > failed = 1; > } else > if (flags & OPT_VERBOSE) > printf("ok\n"); > > if (flags & OPT_VERBOSE) > printf("Checking for robust (PI) mutex glibc support: "); > > if ((ret = lookup_glibc_symbols(syms, 0)) != 0) { > if (flags & OPT_VERBOSE) { > printf(NEWLINE); > lookup_glibc_symbols(syms, flags); > } > failed = 1; > } else > if (flags & OPT_VERBOSE) > printf("ok\n"); > > if (failed) > return FAIL_ROBUST_MUTEX; > > return ret; >} > >/* Test 5: High resolution timers > * > * Verify the system can use high resolution timers. > */ >static int verify_timer(uint32_t flags) >{ > int ret; > char buf[MAX_BUF_LEN]; > FILE *f; > > if (flags & OPT_VERBOSE) > printf("Checking for high resolution timers: "); > > if ((f = fopen("/proc/timer_list", "r")) == NULL) { > if (flags & OPT_VERBOSE) > printf(FAIL_MSG > "/proc/timer_list was not found; kernel too old\n"); > exit(1); > } > > for (ret = 1; !feof(f); fread(buf, 1, MAX_BUF_LEN, f)) { > if ((ret = !((long)strstr(buf, ".hres_active : 1"))) == 0) > break; > } > fclose(f); > > if (ret) { > if (flags & OPT_VERBOSE) > printf(FAIL_MSG > "kernel not configured with hi-res timer support\n"); > return FAIL_ROBUST_MUTEX; > } > > if (flags & OPT_VERBOSE) > printf("ok\n"); > > return ret; >} > >/* Test 6: Clock Resolution > * > * Verify clock_getres returns finer resolution than 200us. > */ >int verify_clock_res(uint32_t flags) >{ > int ret; > struct timespec ts; > > if (flags & OPT_VERBOSE) > printf("Testing for acceptable clock resolution (<=200us): "); > > if ((ret = clock_getres(CLOCK_REALTIME, &ts)) < 0) { > perror("clock_getres"); > return ret; > } > > ret = (ts.tv_sec == 0 && ts.tv_nsec <= 200000) ? 0 : FAIL_CLOCK_RES; > > if (flags & OPT_VERBOSE) { > if (!ret) > printf("ok"); > else > printf(FAIL_MSG > "reporting %ldus", (ts.tv_nsec / 1000)); > } > > return ret; >} > >int main(int argc, char **argv) >{ > int opt; > struct stat buf; > uint32_t flags = 0, ret = 0; > > while ((opt = getopt(argc, argv, "v")) != EOF) { > switch (opt) { > case 'v': > flags |= OPT_VERBOSE; > break; > default: > print_usage(argv[0]); > } > } > > if (optind > argc) > print_usage(argv[0]); > > if (flags & OPT_VERBOSE) { > printf("RTCheck v0.5 - Linux Real-time Environment Checker\n"); > printf("--------------------------------------------------\n"); > } > > if (stat("/proc", &buf)) { > fprintf(stderr, "The /proc interface must be enabled (CONFIG_PROCFS=y) " > "to use this program.\n"); > exit(1); > } > > ret |= verify_memlock(flags); > ret |= verify_sched(flags); > ret |= verify_preempt_rt(flags); > ret |= verify_robust_mutex(flags); > ret |= verify_timer(flags); > ret |= verify_clock_res(flags); > > if (flags & OPT_VERBOSE) { > if (ret) > printf("\nSome tests failed, exiting with " > "status %d\n", ret); > else > printf("\nAll tests passed; RT Java will be " > "permitted to run\n"); > } > > return ret; >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 236962
:
152932
| 154753 |
155906
|
156473
|
156511
|
156512