Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perf log #20

Merged
merged 3 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

# output files for c
*.out
.vscode/*
18 changes: 18 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"configurations": [
{
"name": "linux-gcc-x64",
"includePath": [
"${workspaceFolder}/**"
],
"compilerPath": "/usr/bin/gcc",
"cStandard": "${default}",
"cppStandard": "${default}",
"intelliSenseMode": "linux-gcc-x64",
"compilerArgs": [
""
]
}
],
"version": 4
}
24 changes: 24 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++ Runner: Debug Session",
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": false,
"externalConsole": false,
"cwd": "/home/george/repos/OctopusOS/code",
"program": "/home/george/repos/OctopusOS/code/build/Debug/outDebug",
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
59 changes: 59 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"C_Cpp_Runner.cCompilerPath": "gcc",
"C_Cpp_Runner.cppCompilerPath": "g++",
"C_Cpp_Runner.debuggerPath": "gdb",
"C_Cpp_Runner.cStandard": "",
"C_Cpp_Runner.cppStandard": "",
"C_Cpp_Runner.msvcBatchPath": "",
"C_Cpp_Runner.useMsvc": false,
"C_Cpp_Runner.warnings": [
"-Wall",
"-Wextra",
"-Wpedantic",
"-Wshadow",
"-Wformat=2",
"-Wcast-align",
"-Wconversion",
"-Wsign-conversion",
"-Wnull-dereference"
],
"C_Cpp_Runner.msvcWarnings": [
"/W4",
"/permissive-",
"/w14242",
"/w14287",
"/w14296",
"/w14311",
"/w14826",
"/w44062",
"/w44242",
"/w14905",
"/w14906",
"/w14263",
"/w44265",
"/w14928"
],
"C_Cpp_Runner.enableWarnings": true,
"C_Cpp_Runner.warningsAsError": false,
"C_Cpp_Runner.compilerArgs": [],
"C_Cpp_Runner.linkerArgs": [],
"C_Cpp_Runner.includePaths": [],
"C_Cpp_Runner.includeSearch": [
"*",
"**/*"
],
"C_Cpp_Runner.excludeSearch": [
"**/build",
"**/build/**",
"**/.*",
"**/.*/**",
"**/.vscode",
"**/.vscode/**"
],
"C_Cpp_Runner.useAddressSanitizer": false,
"C_Cpp_Runner.useUndefinedSanitizer": false,
"C_Cpp_Runner.useLeakSanitizer": false,
"C_Cpp_Runner.showCompilationTime": false,
"C_Cpp_Runner.useLinkTimeOptimization": false,
"C_Cpp_Runner.msvcSecureNoWarnings": false
}
3 changes: 3 additions & 0 deletions code/headers.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@

#define SHKEY 300

#define LOG_FILE "scheduler.log"
#define PERF_FILE "scheduler.perf"

//===============================
// ARGUMENTS
//===============================
Expand Down
39 changes: 39 additions & 0 deletions code/log-todos.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# I wrote this to help me remember where am I and what needs to get done

From Scheduler's responsibilties
Report :
1. CPU utilization
2. Avg weighted turnaround time
3. Avg waiting time
4. Standard deviation for avd wieghted TRT

Generate :
1. Scheduler.log
2. Scheduler.perf

Steps:
1. turnaround time (TRT) = finish time - arrival time
2. weighted turnaround time (WTA) = TRT / burst_time
3. avg WTA = Sum(WTA) / N
4. avg waiting = Sum(waiting) / N

then to calc Standard deviation of WTA:
A. calc SS = SUM((WTA - avgWTA)^2)
B. stdDev = sqrt (SS / N)

--- Scheduler.log
# at time {t} process {p} {state} arr {AT} total {burst time} remain {BT - runtime} wait {WT}
---

--- Scheduler.perf (from doc)
CPU utilization = (Total time on non idle tasks) / total time
Avg WTA =
Avg waiting =
Std WTA =
---

NOTES:

Numbers: approx to 2 decimal places
States: started, resumed, stopped, finished
TA & WTA written only at finished state
4 changes: 4 additions & 0 deletions code/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,9 @@ int main(int agrc, char *argv[]) {

raise(SIGTERM);

// log this
//TODO
// logger("finished")

return 0;
}
2 changes: 2 additions & 0 deletions code/process_generator.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,4 +339,6 @@ void sendProcessesToScheduler(queue *processes, int msgQID) {
perror("Error in terminating sending processes to scheduler\n");
exit(-1);
}

//george: call log and print to log file
}
54 changes: 54 additions & 0 deletions code/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ int main(int argc, char *argv[]) {
printf(ANSI_BLUE "==>SCH: My Scheduler Type is %i\n" ANSI_RESET,
(int)schedulerType);

createLogFile();
msgQID = gen_msgQID = initSchGenCom();
schedule(schedulerType, quantem, gen_msgQID);

Expand Down Expand Up @@ -380,6 +381,9 @@ void startProcess(process_t *process) {
kill(process->pid, SIGCONT);
process->state = RUNNING;
process->WT = getClk() - process->AT;

// log this
logger("started", process);
}

/**
Expand All @@ -395,6 +399,9 @@ void preemptProcess(process_t *process) {
kill(process->pid, SIGSTOP);
process->state = STOPPED;
process->LST = getClk();

// log this
logger("stopped", process);
}
}

Expand All @@ -410,6 +417,9 @@ void resumeProcess(process_t *process) {
kill(process->pid, SIGCONT);
process->state = RUNNING;
process->WT += getClk() - process->LST;

// log this
logger("resumed", process);
}
}

Expand Down Expand Up @@ -458,4 +468,48 @@ void sigUsr1Handler(int signum) {
killedProcess = wait(&status);
printf(ANSI_GREY "==>SCH: Process %d terminated\n" ANSI_RESET, killedProcess);
currentProcess = NULL;

// log this
//TODO
// logger("finished", )
}

void createLogFile()
{
FILE * logFileptr = fopen(LOG_FILE, "w");
if (logFileptr == NULL)
{
perror("Can't Create Log File");
exit(-1);
}

printf("Started Logging\n");
fclose(logFileptr);
}

void logger(char * msg, process_t * p)
{

// appending to the previously created file
FILE * logFileptr = fopen(LOG_FILE, "a");

if (logFileptr == NULL)
{
perror("Can't Open Log File");
exit(-1);
}
int clk = getClk();
float WTA = p->TA / (float) p->BT;

fprintf(logFileptr, "At time %i process %i %s arr %i total %i remain %i wait %i",
clk, p->id, msg, p->AT, p->BT, *p->RT, p->WT);

if (strcmp(msg, "finished") == 0)
{
fprintf(logFileptr, " TA %i WTA %.2f", p->TA, WTA);
}

fprintf(logFileptr, "\n");

fclose(logFileptr);
}
7 changes: 7 additions & 0 deletions code/scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,10 @@ void resumeProcess(process_t *process);
// it's termination
int initSchProQ();
void sigUsr1Handler(int signum);

//==============================
// Logging Functions
//==============================

void createLogFile();
void logger(char * action, process_t* process_pcb);
6 changes: 6 additions & 0 deletions code/scheduler.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
At time 3 process 1 started arr 2 total 20 remain 20 wait 1
At time 6 process 1 stopped arr 2 total 20 remain 17 wait 1
At time 6 process 2 started arr 5 total 10 remain 10 wait 1
At time 17 process 3 started arr 9 total 15 remain 15 wait 8
At time 32 process 4 started arr 11 total 17 remain 17 wait 21
At time 50 process 1 started arr 2 total 20 remain 16 wait 48