From 1c186d1fa3a9086b894239da7911e57c09677c98 Mon Sep 17 00:00:00 2001 From: Fabio Niephaus Date: Sun, 6 Nov 2016 17:03:39 +0100 Subject: [PATCH] Add set_rtprio_limit utility for OpenSmalltalk VMs --- .travis.yml | 2 +- tests/all_tests.sh | 2 ++ tests/utils_tests.sh | 17 +++++++++++++++ utils/set_rtprio_limit.c | 46 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+), 1 deletion(-) mode change 100644 => 100755 tests/all_tests.sh create mode 100755 tests/utils_tests.sh create mode 100644 utils/set_rtprio_limit.c diff --git a/.travis.yml b/.travis.yml index 9590a8c1..b025c37b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -41,7 +41,7 @@ matrix: - language: bash smalltalk: sudo: false - script: bash tests/all_tests.sh + script: tests/all_tests.sh # Test that smalltalkCI can fail - smalltalk: Squeak-5.0 diff --git a/tests/all_tests.sh b/tests/all_tests.sh old mode 100644 new mode 100755 index 970a2469..be4135ba --- a/tests/all_tests.sh +++ b/tests/all_tests.sh @@ -12,5 +12,7 @@ echo "======================================================" echo "======================================================" "${BASE}/squeak_tests.sh" || status=$? echo "======================================================" +"${BASE}/utils_tests.sh" || status=$? +echo "======================================================" exit "${status}" \ No newline at end of file diff --git a/tests/utils_tests.sh b/tests/utils_tests.sh new file mode 100755 index 00000000..930dcf9b --- /dev/null +++ b/tests/utils_tests.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +readonly BASE="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +source "${BASE}/helpers.sh" + + +test_set_rtprio() { + if [[ "$(uname -s)" != "Linux" ]]; then + return + fi + gcc -o "set_rtprio_limit" "${BASE}/utils/set_rtprio_limit.c" + if [[ ! -f "set_rtprio_limit" ]]; then + fail "set_rtprio_limit should exist" + fi +} + +source "${BASE}/lib/shunit2" diff --git a/utils/set_rtprio_limit.c b/utils/set_rtprio_limit.c new file mode 100644 index 00000000..5ab72771 --- /dev/null +++ b/utils/set_rtprio_limit.c @@ -0,0 +1,46 @@ +// Set rtprio to 2:2 for a given pid (required to run OpenSmalltalk VMs). + +#define _GNU_SOURCE +#define _FILE_OFFSET_BITS 64 +#include +#include +#include +#include +#include + +#define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \ + } while (0) + +int main(int argc, char *argv[]) { + struct rlimit old, new; + struct rlimit *newp; + pid_t pid; + + if (!(argc == 2)) { + fprintf(stderr, "Usage: %s \n", argv[0]); + exit(EXIT_FAILURE); + } + + pid = atoi(argv[1]); /* PID of target process */ + + new.rlim_cur = 2; + new.rlim_max = 2; + newp = &new; + + /* Set RTPRIO limit of target process; retrieve and display + previous limit */ + + if (prlimit(pid, RLIMIT_RTPRIO, newp, &old) == -1) + errExit("prlimit-rtprio-1"); + printf("Previous limits: soft=%lld; hard=%lld\n", + (long long) old.rlim_cur, (long long) old.rlim_max); + + /* Retrieve and display new RTPRIO limit */ + + if (prlimit(pid, RLIMIT_RTPRIO, NULL, &old) == -1) + errExit("prlimit-rtprio-2"); + printf("New limits: soft=%lld; hard=%lld\n", + (long long) old.rlim_cur, (long long) old.rlim_max); + + exit(EXIT_SUCCESS); +} \ No newline at end of file