slow down boinc

Questions and Answers : Unix/Linux : slow down boinc
Message board moderation

To post messages, you must log in.

AuthorMessage
arris

Send message
Joined: 24 May 99
Posts: 1
Credit: 69
RAC: 0
Austria
Message 450162 - Posted: 4 Nov 2006, 10:27:14 UTC

until a fixed version is out may you can try this solution

compile slomo.c as shared lib and preload it
Makefile, slomo.c and startscript included.

in the script boinc-run.sh you have to change the pathes for your setup

Makefile
-----<CUT>-----
CC=gcc
CFLAGS=-O2 -Wall
LIBADD_DL=-ldl
OPTIONS=-shared -fpic

all:
$(CC) $(CFLAGS) $(LIBADD_DL) $(OPTIONS) slomo.c -o slomo.so
strip slomo.so

clean:
rm -f *~
rm -f slomo.so
-----<CUT>-----

slomo.c
-----<CUT>-----
/*
* 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; either version 2 of the License, or
* (at your option) any later version.
*
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#define HIJACKER_VERSION "0.1"

#define _GNU_SOURCE

#include <dlfcn.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <syscall.h>
#include <signal.h>
#include <errno.h>
static int childs,counter;
static int pidof_childs[255];
static void hijacker_init() __attribute__ ((constructor));

#define DEBUG(level, format, ...) \\
do { if (level<DEBUG_HIJACKER) fprintf (stderr, format, ## __VA_ARGS__); } while(0)

//debug
// 0 - no messages
// 1 - only error messages that probably explain failures (recommended)
// 2 - more output on opening/closing sound devices
// 3 - lots of messages on open/close actions
#define DEBUG_HIJACKER 0

/* original C Library functions */
typedef pid_t (*orig_waitpid_ptr)(pid_t pid, int *status, int options);
typedef pid_t (*orig_fork_ptr)(void);

static orig_waitpid_ptr orig_waitpid;
static orig_fork_ptr orig_fork;

static void rescue_old_libcalls(void);
static void print_config(void);



int waitpid(pid_t pid, int *status, int options)
{
pid_t res;
int i;
counter = (counter < 4) ? counter+1 : 0;

if(options){
DEBUG(2,"hijacker: waitpid called for pid %d otions=true\\n", pid);
} else {
DEBUG(2,"hijacker: waitpid called for pid %d otions=false\\n", pid);
}
DEBUG(2,"hijacker: waitpid called , have %d childs counter %d\\n",childs, counter);

for(i=1;i<=childs;i++)
{
switch(counter) {
case 0:
if (kill(pidof_childs[i],SIGCONT)!=0) {
fprintf(stderr,"Process %d dead!\\n",pidof_childs[i]);
} else {
DEBUG(2,"hijacker: SIGCONT success for %d\\n",pidof_childs[i]);
}
break;
default:
if (kill(pidof_childs[i],SIGSTOP)!=0) {
fprintf(stderr,"Process %d dead!\\n",pidof_childs[i]);
} else {
DEBUG(2,"hijacker: SIGSTOP success for %d\\n",pidof_childs[i]);
}
}

}
res = orig_waitpid(pid, status, options);

return res;
}

pid_t fork(void) {
pid_t pid;
pid = orig_fork();
sleep(1);
DEBUG(1,"Hijack: Fork PID %i | PPID %i child %d\\n",getpid(),getppid(), pid);
if(pid == 0) {

DEBUG(1,"Hijack start cpulimit -p %i -l 20 -z for %d. child\\n",getpid(), childs);

} else if(pid > 0) {
DEBUG(1,"Hijack: Parent PID %i | Process %i forked (%d)\\n",getppid(),getpid(), pid);
childs++ ;
pidof_childs[childs] = pid;
} else {
DEBUG(1,"Hijack: Fork Failed\\n");
perror("fork");
}
return(pid);
}


/* Save the original functions */
static void rescue_old_libcalls()
{
orig_waitpid = (orig_waitpid_ptr)dlsym(RTLD_NEXT,"waitpid");
orig_fork = (orig_fork_ptr)dlsym(RTLD_NEXT,"fork");
}

static void print_config(){

}

static void hijacker_init(void) {
static int isinit=0;

if (isinit) return;
isinit++;
DEBUG(1,"hijacker: v%s initializing.\\n",HIJACKER_VERSION);
DEBUG(1,"hijacker: hijacker_init PID %i | PPID %i \\n",getpid(),getppid());
rescue_old_libcalls();
print_config();
}
-----<CUT>-----

boinc-run.sh
-----<CUT>-----
#!/bin/sh

export LD_PRELOAD=$(pwd)/slomo.so ; cd ~/BOINC && ./run_client && export LD_PRELOAD=
-----<CUT>-----
ID: 450162 · Report as offensive

Questions and Answers : Unix/Linux : slow down boinc


 
©2025 University of California
 
SETI@home and Astropulse are funded by grants from the National Science Foundation, NASA, and donations from SETI@home volunteers. AstroPulse is funded in part by the NSF through grant AST-0307956.