diff --git a/mentos/CMakeLists.txt b/mentos/CMakeLists.txt index af565fa..13fc177 100644 --- a/mentos/CMakeLists.txt +++ b/mentos/CMakeLists.txt @@ -127,6 +127,7 @@ set(KERNEL_SOURCES src/io/debug.c src/io/proc_video.c src/io/proc_running.c + src/io/proc_feedback.c src/io/proc_system.c src/io/vga/vga.c src/ipc/msg.c @@ -166,6 +167,7 @@ set(KERNEL_SOURCES src/descriptor_tables/tss.c src/descriptor_tables/tss.S src/process/scheduler_algorithm.c + src/process/scheduler_feedback.c src/process/scheduler.c src/process/process.c src/process/wait.c diff --git a/mentos/inc/io/proc_modules.h b/mentos/inc/io/proc_modules.h index 123edc8..5712a5f 100644 --- a/mentos/inc/io/proc_modules.h +++ b/mentos/inc/io/proc_modules.h @@ -14,3 +14,5 @@ int procv_module_init(); /// @brief Initialize the procfs system files. /// @return 0 on success, 1 on failure. int procs_module_init(); + +int procfb_module_init(); diff --git a/mentos/inc/process/scheduler_feedback.h b/mentos/inc/process/scheduler_feedback.h new file mode 100644 index 0000000..853bb39 --- /dev/null +++ b/mentos/inc/process/scheduler_feedback.h @@ -0,0 +1,13 @@ +/// @file scheduler_feedback.h +/// @author Enrico Fraccaroli (enry.frak@gmail.com) +/// @brief + +#pragma once + +#include "sys/types.h" + +void writeFeedback(pid_t pid, char name[]); + +/// @brief Initialize the scheduler feedback system. +/// @return 1 on success, 0 on failure. +int scheduler_feedback_init(); diff --git a/mentos/src/io/proc_feedback.c b/mentos/src/io/proc_feedback.c new file mode 100644 index 0000000..f2b6c3c --- /dev/null +++ b/mentos/src/io/proc_feedback.c @@ -0,0 +1,50 @@ +/// @file proc_feedback.c +/// @brief Contains callbacks for procfs system files. +/// @copyright (c) 2014-2022 This file is distributed under the MIT License. +/// See LICENSE.md for details. + +#include "fs/procfs.h" +#include "process/process.h" +#include "sys/errno.h" +#include "io/debug.h" +#include "string.h" + +static ssize_t procfb_read(vfs_file_t *file, char *buf, off_t offset, size_t nbyte) +{ + return 0; +} + +/// Filesystem general operations. +static vfs_sys_operations_t procfb_sys_operations = { + .mkdir_f = NULL, + .rmdir_f = NULL, + .stat_f = NULL +}; + +/// Filesystem file operations. +static vfs_file_operations_t procfb_fs_operations = { + .open_f = NULL, + .unlink_f = NULL, + .close_f = NULL, + .read_f = procfb_read, + .write_f = NULL, + .lseek_f = NULL, + .stat_f = NULL, + .ioctl_f = NULL, + .getdents_f = NULL +}; + +int procfb_module_init() +{ + // Create the file. + proc_dir_entry_t *file = proc_create_entry("feedback", NULL); + if (file == NULL) { + pr_err("Cannot create `/proc/feedback`.\n"); + return 1; + } + pr_debug("Created `/proc/feedback` (%p)\n", file); + // Set the specific operations. + file->sys_operations = &procfb_sys_operations; + file->fs_operations = &procfb_fs_operations; + return 0; +} diff --git a/mentos/src/kernel.c b/mentos/src/kernel.c index a051c1e..abe8ef7 100644 --- a/mentos/src/kernel.c +++ b/mentos/src/kernel.c @@ -31,6 +31,7 @@ #include "drivers/keyboard/keymap.h" #include "drivers/ps2.h" #include "process/scheduler.h" +#include "process/scheduler_feedback.h" #include "hardware/timer.h" #include "fs/vfs.h" #include "devices/fpu.h" @@ -344,6 +345,24 @@ int kmain(boot_info_t *boot_informations) } print_ok(); + //========================================================================== + pr_notice("Initialize scheduler feedback system...\n"); + printf("Initialize scheduler feedback system..."); + if (!scheduler_feedback_init()) { + print_fail(); + return 1; + } + print_ok(); + + //========================================================================== + pr_notice("Initialize scheduler feedback system (2)...\n"); + printf("Initialize scheduler feedback system (2)..."); + if (procfb_module_init()) { + print_fail(); + return 1; + } + print_ok(); + //========================================================================== pr_notice("Creating init process...\n"); printf("Creating init process..."); diff --git a/mentos/src/process/scheduler_algorithm.c b/mentos/src/process/scheduler_algorithm.c index 9c0008f..0bed6b9 100644 --- a/mentos/src/process/scheduler_algorithm.c +++ b/mentos/src/process/scheduler_algorithm.c @@ -17,9 +17,7 @@ #include "klib/list_head.h" #include "process/wait.h" #include "process/scheduler.h" - -//scheduler feedback files -#include "feedbackScheduler.c" +#include "process/scheduler_feedback.h" /// @brief Updates task execution statistics. /// @param task the task to update. diff --git a/mentos/src/process/feedbackScheduler.c b/mentos/src/process/scheduler_feedback.c similarity index 72% rename from mentos/src/process/feedbackScheduler.c rename to mentos/src/process/scheduler_feedback.c index 76c8658..01e6aa1 100644 --- a/mentos/src/process/feedbackScheduler.c +++ b/mentos/src/process/scheduler_feedback.c @@ -1,4 +1,4 @@ -/// @file feedbackScheduler.c +/// @file scheduler_feedback.c /// @brief Manage the current PID for the scheduler feedback session /// @copyright (c) 2014-2022 This file is distributed under the MIT License. /// See LICENSE.md for details. @@ -17,11 +17,14 @@ Questa e' una versione di prova in cui registriamo una brevissima sessione di so Istruzioni relative ai parametri della funzione start (che sono work in progress) sono in start.c */ +#include "process/scheduler_feedback.h" + #include "fcntl.h" #include "stdio.h" #include "fs/vfs.h" #include "string.h" +#define FEEDBACK_FILENAME "/home/user/feedback.txt" // Size of the buffer. #define BUFFER_SIZE 256 @@ -30,13 +33,12 @@ Istruzioni relative ai parametri della funzione start (che sono work in progress //Variabili Globali #define MAX_STORAGE 10 -int count = 0; -pid_t PID_BUFFER[MAX_STORAGE] = {0}; +int count = 0; +pid_t PID_BUFFER[MAX_STORAGE] = { 0 }; char PID_NAME[MAX_STORAGE][MAX_SIZE_NAME]; int countChar(char[]); - /* PID 1 --> INIT PID 2 --> KTHREADD @@ -46,51 +48,44 @@ int countChar(char[]); Funzione che viene chiamata da scheduler_algorithm dopo aver scelto il prossimo processo da eseguire */ void writeFeedback(pid_t pid, char name[]) -{ +{ int brake = 0; char start[] = "start"; //analizzo se nome del PID passato come argomento corrisponde al comando START - for(int i = 0 ; i < countChar(name) && brake == 0; i++) - { - if(start[i] != name[i]) - { + for (int i = 0; i < countChar(name) && brake == 0; i++) { + if (start[i] != name[i]) { brake = 1; } } //Entra solo una volta, dopo aver finito la sessione (riempito il buffer) - if(brake == 0 && count == MAX_STORAGE-1) - { + if (brake == 0 && count == MAX_STORAGE - 1) { //RESET BUFFER - for(int i = 0; i < MAX_STORAGE; i++) - { + for (int i = 0; i < MAX_STORAGE; i++) { PID_BUFFER[i] = 0; } count = 0; - } - //Se prima volta e' start bene, proseguiamo siccome brake e' zero, + //Se prima volta e' start bene, proseguiamo siccome brake e' zero, //le successive brake NON zero ma count > 0 poiche start passato in precedenza //Opportuno controllo per non sforare il MAX_STORAGE della struttura dati che utilizziamo - if(count != MAX_STORAGE-1 && (count != 0 || brake == 0 )) - { + if (count != MAX_STORAGE - 1 && (count != 0 || brake == 0)) { //REGISTRAZIONE PID IN BUFFER PID_BUFFER[count] = pid; - strcpy(PID_NAME[count],name); + strcpy(PID_NAME[count], name); count++; } //QUI SE BUFFER PIENO SCRIVO SU FILE - if(count == MAX_STORAGE-1) - { + if (count == MAX_STORAGE - 1) { mode_t mode = 000777; char buffer[BUFFER_SIZE]; const char *namef = "/home/user/feedback.txt"; - ssize_t offset = sizeof(char)*38; + ssize_t offset = sizeof(char) * 38; char temp[6]; //max PID 99999 // NOTE: You should check if the file exists, or create it, during the boot @@ -102,36 +97,41 @@ void writeFeedback(pid_t pid, char name[]) printf("Error: Failed to open feedback file."); } - for(int i=0; i < MAX_STORAGE; i++) - { - itoa(temp,PID_BUFFER[i],10); - offset += vfs_write(file, temp, offset, sizeof(char)*countChar(temp)); - offset += vfs_write(file, " ", offset, sizeof(char)*3); - offset += vfs_write(file, PID_NAME[i], offset, sizeof(char)*countChar(PID_NAME[i])); + for (int i = 0; i < MAX_STORAGE; i++) { + itoa(temp, PID_BUFFER[i], 10); + offset += vfs_write(file, temp, offset, sizeof(char) * countChar(temp)); + offset += vfs_write(file, " ", offset, sizeof(char) * 3); + offset += vfs_write(file, PID_NAME[i], offset, sizeof(char) * countChar(PID_NAME[i])); offset += vfs_write(file, "\n", offset, sizeof(char)); //ripristino array temp - for(int j=0; j < 5; j++) - { + for (int j = 0; j < 5; j++) { temp[j] = 0; } - } printf("End Recording\n"); - vfs_close(file); + vfs_close(file); count = 0; } - -} - +} /* Funzione che conta caratteri del array di char passato */ -int countChar(char name[]){ - int ct = 0; - while(name[ct]!='\0'){ +int countChar(char name[]) +{ + int ct = 0; + while (name[ct] != '\0') { ct++; } return ct; -} \ No newline at end of file +} + +int scheduler_feedback_init() +{ + // + mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; + // + vfs_file_t *feedback = vfs_creat(FEEDBACK_FILENAME, mode); + return 1; +}