#!/usr/bin/stap # # Request Based Priority Elevation RBPE Version 0.5 # Copyright (C) 2010 Mohammad Nikseresht # mniksere (at) scs.carleton.ca # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. # # Make sure that you have SystemTap intalled properly # the run the script as root with -g command line option: # YourPrompt>./chageSchedule.stp -g # # %{#include %} function loadavg() %{ THIS->__retvalue = (long)avenrun[0]; %} function my_pid_task(pid) %{ struct task_struct *tkp ; struct pid *pp; pid_t pid = (pid_t) (long) THIS->pid ; rcu_read_lock() ; pp = find_vpid(pid) ; tkp = pid_task(pp , PIDTYPE_PID) ; rcu_read_unlock() ; THIS->__retvalue = (long) tkp ; %} function man_prio(taskp,newp) %{ struct task_struct *tkp = (struct task_struct *) (long) THIS->taskp ; set_user_nice(tkp , THIS->newp) ; %} function ret_prio(taskp) %{ struct task_struct *tkp = (struct task_struct *) (long) THIS->taskp ; THIS->__retvalue = (tkp->prio - MAX_RT_PRIO) ; %} global sw,tm, temp, pidList ; global DELAY = 0; global MAX_NICE1 = 0 ; global MAX_NICE2 = 0; probe socket.receive{ if (size >0 ){ myPid = pid(); pidList[myPid]= myPid ; if(family == 1){ NICE = MAX_NICE1 ; } else{ NICE = MAX_NICE2 ; } sw[myPid] = NICE; tm[myPid]= gettimeofday_ms() ; p = task_current(); man_prio(p,NICE) ; } } probe syscall.sendfile { myPid = pid(); sw[myPid] = MAX_NICE2 ; tm[myPid]= gettimeofday_ms() ; p = task_current(); man_prio(p,MAX_NICE2) ; } probe syscall.fork.return{ task = task_current(); myPr = ret_prio(task) ; if (($return > 0) && (myPr <20)){ pidList[$return] = $return ; sw[$return] = myPr - 20; tm[$return]= gettimeofday_ms() ; } } probe syscall.poll{ tempload = loadavg(); if (tempload < 1600){ MAX_NICE1 = 0 ; MAX_NICE2 = 0 DELAY = 0 ; } else if (tempload <= 3000){ MAX_NICE1 = -1 ; MAX_NICE2 = 0 ; DELAY = 200; } else if (tempload <= 5000){ MAX_NICE1 = -2 ; MAX_NICE2 = -1 ; DELAY = 300; } else if (tempload <= 8000){ MAX_NICE1 = -4; MAX_NICE2 = -2 ; DELAY = 400; } else if (tempload <= 12000){ MAX_NICE1 = -6; MAX_NICE2 = -3 ; DELAY = 500; } else if (tempload <= 16000){ MAX_NICE1 = -7; MAX_NICE2 = -4 ; DELAY = 600; } else { MAX_NICE1 = -15 MAX_NICE2= -5 ; DELAY = 600 ; } i = 0 ; tempTask ; t = gettimeofday_ms() ; foreach (pd in pidList) if (((t - tm[pd]) > DELAY) && (sw[pd] !=0) ){ tm[pd] = gettimeofday_ms() ; sw[pd] += 1 ; tempTask = my_pid_task(pd); if (tempTask){ man_prio(tempTask,sw[pd]); if (sw[pd] == 0){ temp[i] = pd; i++; } }//end if else{ temp[i] = pd; i++; }//end else } //end if for (j = 0 ; j < i ; j++){ delete sw[temp[j]]; delete tm[temp[j]]; delete pidList[temp[j]] ; delete temp[j]; } } probe end { foreach (pd in pidList){ tempTask = my_pid_task(pd); man_prio(tempTask,0); } delete sw ; delete tm ; delete temp ; }