Skip to content

Commit

Permalink
Livestat: A User Tool to dynamically display basekernel stats (#252)
Browse files Browse the repository at this point in the history
* changed the head command

* changed the head num to 20001

* added bcache stats

* added syscall for bcache stats

* added bcache stats test

* added syscall for bcache stats

* move bcache stats struct to stats.h

* added bcache_flush syscall

* added get stats for objects

* added stats collection

* added driver and object stats collection

* fixed syntax

* added calls for stats collection

* added dev driver stats to enum

* added stats

* added stats

* added stats

* added strdup

* init commit

* remove bcachetest

* added livestat and statworkload

* added stats collection

* added strdup

* added more stats structs

* added stats collection calls

* removed objectstats

* removed object stats

* removed structs related to object syscalls

* Revert "added stats"

This reverts commit 42c7222.

* Revert "added stats"

This reverts commit f290dec.

* removed the device statistics

* Revert "added stats collection"

This reverts commit 87ee455.

* removed object stats functions

* Revert "added get stats for objects"

This reverts commit 5ead44f.

* changed bar graphs

* minor comment changes

* removed ata include, added stats include

* added device_driver_lookup funct

* modified driver stats to take in const char * name

* added pointer and string checking to driver stats

* fixed redefinition error from merge

* fixed strdup function

* pass args by pointers
  • Loading branch information
jmazanec15 authored and dthain committed Sep 6, 2019
1 parent 088b61c commit bf596aa
Show file tree
Hide file tree
Showing 13 changed files with 562 additions and 48 deletions.
32 changes: 19 additions & 13 deletions include/kernel/stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,30 @@
#include "kernel/syscall.h"

struct system_stats {
uint32_t time;
uint32_t blocks_read[4];
uint32_t blocks_written[4];
int time;
int blocks_read[4];
int blocks_written[4];
};

struct object_stats {
uint32_t reads;
uint32_t writes;
uint64_t bytes_read;
uint64_t bytes_written;
struct device_driver_stats {
int blocks_written;
int blocks_read;
};

struct bcache_stats {
int read_hits;
int read_misses;
int write_hits;
int write_misses;
int writebacks;
};

struct process_stats {
uint32_t blocks_read;
uint32_t blocks_written;
uint32_t bytes_read;
uint32_t bytes_written;
uint32_t syscall_count[MAX_SYSCALL];
int blocks_read;
int blocks_written;
int bytes_read;
int bytes_written;
int syscall_count[MAX_SYSCALL];
};

#endif
3 changes: 3 additions & 0 deletions include/kernel/syscall.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ typedef enum {
SYSCALL_OBJECT_SET_BLOCKING,
SYSCALL_OBJECT_MAX,
SYSCALL_SYSTEM_STATS,
SYSCALL_BCACHE_STATS,
SYSCALL_BCACHE_FLUSH,
SYSCALL_SYSTEM_TIME,
SYSCALL_SYSTEM_RTC,
SYSCALL_DEVICE_DRIVER_STATS,
SYSCALL_CHDIR,
MAX_SYSCALL // must be the last element in the enum
} syscall_t;
Expand Down
1 change: 1 addition & 0 deletions include/library/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ void strncpy(char *d, const char *s, unsigned length);
char * strdup(const char *s);
int strcmp(const char *a, const char *b);
int strncmp(const char *a, const char *b, unsigned length);
char *strdup(const char *s);
unsigned strlen(const char *s);
char *strcat(char *d, const char *s);
char *uint_to_string(uint32_t u, char *str);
Expand Down
7 changes: 6 additions & 1 deletion include/library/syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ int syscall_object_size(int fd, int * dims, int n);
int syscall_object_copy( int src, int dst );
int syscall_object_remove( int fd, const char *name );
int syscall_object_close(int fd);
int syscall_object_stats(int fd, struct object_stats *stats );
int syscall_object_set_tag(int fd, char *tag);
int syscall_object_get_tag(int fd, char *buffer, int buffer_size);
int syscall_object_set_blocking(int fd, int b);
Expand All @@ -60,9 +59,15 @@ int syscall_object_max();
/* Syscalls that query or affect the whole system state. */

int syscall_system_stats(struct system_stats *s);
int syscall_bcache_stats(struct bcache_stats *s);

int syscall_bcache_flush();

int syscall_system_time( uint32_t *t );
int syscall_system_rtc( struct rtc_time *t );

int syscall_device_driver_stats(char * name, struct device_driver_stats * stats);

/*
These system calls are carryovers from Unix-like thinking
and need to be reworked to fit the kernel object model.
Expand Down
9 changes: 1 addition & 8 deletions kernel/bcache.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ See the file LICENSE for details.
#define BCACHE_H

#include "device.h"
#include "kernel/stats.h"

int bcache_read( struct device *d, char *data, int blocks, int offset );
int bcache_write( struct device *d, const char *data, int blocks, int offset );
Expand All @@ -19,14 +20,6 @@ void bcache_flush_block( struct device *d, int block );
void bcache_flush_device( struct device *d );
void bcache_flush_all();

struct bcache_stats {
unsigned read_hits;
unsigned read_misses;
unsigned write_hits;
unsigned write_misses;
unsigned writebacks;
};

void bcache_get_stats( struct bcache_stats *s );

#endif
59 changes: 45 additions & 14 deletions kernel/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ Copyright (C) 2016-2019 The University of Notre Dame
This software is distributed under the GNU General Public License.
See the file LICENSE for details.
*/

#include "device.h"
#include "string.h"
#include "page.h"
#include "kmalloc.h"

#include "kernel/stats.h"
#include "kernel/types.h"
#include "kernel/error.h"

Expand All @@ -26,6 +26,7 @@ struct device {
void device_driver_register( struct device_driver *d )
{
d->next = driver_list;
d->stats = (struct device_driver_stats){0};
driver_list = d;
}

Expand Down Expand Up @@ -59,16 +60,9 @@ struct device *device_open( const char *name, int unit )
int nblocks, block_size;
char info[64];

struct device_driver *dd = driver_list;

for(dd=driver_list;dd;dd=dd->next) {
if(!strcmp(dd->name,name)) {
if(dd->probe(unit,&nblocks,&block_size,info)) {
return device_create(dd,unit,nblocks,block_size);
} else {
return 0;
}
}
struct device_driver *dd = device_driver_lookup(name);
if (dd && dd->probe(unit,&nblocks,&block_size,info)) {
return device_create(dd,unit,nblocks,block_size);
}

return 0;
Expand Down Expand Up @@ -99,26 +93,41 @@ void device_close( struct device *d )

int device_read(struct device *d, void *data, int size, int offset)
{
int status;
if(d->driver->read) {
return d->driver->read(d->unit,data,size*d->multiplier,offset*d->multiplier);
status = d->driver->read(d->unit,data,size*d->multiplier,offset*d->multiplier);
if (status) {
d->driver->stats.blocks_read += size*d->multiplier; // number of blocks
}
return status;
} else {
return KERROR_NOT_IMPLEMENTED;
}
}

int device_read_nonblock(struct device *d, void *data, int size, int offset)
{
int status;
if(d->driver->read_nonblock) {
return d->driver->read_nonblock(d->unit,data,size*d->multiplier,offset*d->multiplier);
status = d->driver->read_nonblock(d->unit,data,size*d->multiplier,offset*d->multiplier);
if (status) {
d->driver->stats.blocks_read += size*d->multiplier; // number of blocks
}
return status;
} else {
return KERROR_NOT_IMPLEMENTED;
}
}

int device_write(struct device *d, const void *data, int size, int offset)
{
int status;
if(d->driver->write) {
return d->driver->write(d->unit,data,size*d->multiplier,offset*d->multiplier);
status = d->driver->write(d->unit,data,size*d->multiplier,offset*d->multiplier);
if (!status) {
d->driver->stats.blocks_written += size*d->multiplier;
}
return status;
} else {
return KERROR_NOT_IMPLEMENTED;
}
Expand All @@ -143,3 +152,25 @@ const char * device_name( struct device *d )
{
return d->driver->name;
}

struct device_driver * device_driver_lookup(const char *name)
{
struct device_driver *dd = driver_list;
for(dd=driver_list; dd; dd=dd->next) {
if(!strcmp(dd->name, name)) {
break;
}
}
return dd;
}

void device_driver_get_stats(const char * name, struct device_driver_stats * s)
{
/* Get the device driver */
struct device_driver *dd = device_driver_lookup(name);

/* Copy stats into struct */
if (dd) {
memcpy(s, &(dd->stats), sizeof(*s));
}
}
5 changes: 5 additions & 0 deletions kernel/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ See the file LICENSE for details.
#ifndef DEVICE_H
#define DEVICE_H

#include "kernel/stats.h"
#include "kernel/types.h"

struct device_driver {
Expand All @@ -16,6 +17,7 @@ struct device_driver {
int (*read_nonblock) ( int unit, void *buffer, int nblocks, int block_offset);
int (*write) ( int unit, const void *buffer, int nblocks, int block_offset);
int multiplier;
struct device_driver_stats stats;
struct device_driver *next;
};

Expand All @@ -33,4 +35,7 @@ int device_nblocks( struct device *d );
int device_unit( struct device *d );
const char * device_name( struct device *d );

void device_driver_get_stats(const char * name, struct device_driver_stats * s);
struct device_driver * device_driver_lookup(const char *name);

#endif
37 changes: 29 additions & 8 deletions kernel/syscall_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ See the file LICENSE for details.
#include "ata.h"
#include "graphics.h"
#include "is_valid.h"
#include "bcache.h"

/*
syscall_handler() is responsible for decoding system calls
Expand Down Expand Up @@ -504,11 +505,6 @@ int sys_object_close(int fd)
return 0;
}

int sys_object_stats( int fd, struct object_stats *stats )
{
return KERROR_NOT_IMPLEMENTED;
}

int sys_object_set_tag(int fd, char *tag)
{
if(!is_valid_object(fd)) return KERROR_INVALID_OBJECT;
Expand Down Expand Up @@ -570,6 +566,19 @@ int sys_system_stats(struct system_stats *s)
return 0;
}

int sys_bcache_stats(struct bcache_stats * s)
{
if(!is_valid_pointer(s,sizeof(*s))) return KERROR_INVALID_ADDRESS;
bcache_get_stats( s );
return 0;
}

int sys_bcache_flush()
{
bcache_flush_all();
return 0;
}

int sys_system_time( uint32_t *tm )
{
if(!is_valid_pointer(tm,sizeof(*tm))) return KERROR_INVALID_ADDRESS;
Expand All @@ -586,6 +595,15 @@ int sys_system_rtc( struct rtc_time *t )
return 0;
}

int sys_device_driver_stats(const char * name, struct device_driver_stats * stats)
{
if(!is_valid_string(name)) return KERROR_INVALID_ADDRESS;
if(!is_valid_pointer(stats,sizeof(*stats))) return KERROR_INVALID_ADDRESS;

device_driver_get_stats(name, stats);
return 0;
}

int sys_chdir(const char *path)
{
if(!is_valid_path(path)) return KERROR_INVALID_PATH;
Expand Down Expand Up @@ -667,8 +685,6 @@ int32_t syscall_handler(syscall_t n, uint32_t a, uint32_t b, uint32_t c, uint32_
return sys_object_remove(a,(const char*)b);
case SYSCALL_OBJECT_CLOSE:
return sys_object_close(a);
case SYSCALL_OBJECT_STATS:
return sys_object_stats(a, (struct object_stats *) b);
case SYSCALL_OBJECT_SET_TAG:
return sys_object_set_tag(a, (char *) b);
case SYSCALL_OBJECT_GET_TAG:
Expand All @@ -683,11 +699,16 @@ int32_t syscall_handler(syscall_t n, uint32_t a, uint32_t b, uint32_t c, uint32_
return sys_object_copy(a,b);
case SYSCALL_SYSTEM_STATS:
return sys_system_stats((struct system_stats *) a);
case SYSCALL_BCACHE_STATS:
return sys_bcache_stats((struct bcache_stats *) a);
case SYSCALL_BCACHE_FLUSH:
return sys_bcache_flush();
case SYSCALL_SYSTEM_TIME:
return sys_system_time((uint32_t*)a);
case SYSCALL_SYSTEM_RTC:
return sys_system_rtc((struct rtc_time *) a);

case SYSCALL_DEVICE_DRIVER_STATS:
return sys_device_driver_stats((char *) a, (struct device_driver_stats *) b);
case SYSCALL_CHDIR:
return sys_chdir((const char *) a);
default:
Expand Down
8 changes: 5 additions & 3 deletions library/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ See the file LICENSE for details.

#include "kernel/types.h"
#include "kernel/ascii.h"
#include "library/malloc.h"
#include "library/string.h"
#include "library/malloc.h"
#include "stdarg.h"
Expand All @@ -28,11 +29,12 @@ void strncpy(char *d, const char *s, unsigned length)

char * strdup(const char *s)
{
char * d = (char *)malloc(strlen(s) * sizeof(char));
char * d = (char *)malloc((strlen(s)+1) * sizeof(char));
char * tmp = d;
while(*s) {
*d++ = *s++;
*tmp++ = *s++;
}
*d = 0;
*tmp = 0;
return d;
}

Expand Down
15 changes: 15 additions & 0 deletions library/syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,16 @@ int syscall_system_stats(struct system_stats *s)
return syscall(SYSCALL_SYSTEM_STATS, (uint32_t) s, 0, 0, 0, 0);
}

int syscall_bcache_stats(struct bcache_stats *bstats)
{
return syscall(SYSCALL_BCACHE_STATS, (uint32_t) bstats, 0, 0, 0, 0);
}

int syscall_bcache_flush()
{
return syscall(SYSCALL_BCACHE_FLUSH, 0, 0, 0, 0, 0);
}

int syscall_system_time( uint32_t *t )
{
return syscall(SYSCALL_SYSTEM_TIME, (uint32_t)t, 0, 0, 0, 0);
Expand All @@ -203,6 +213,11 @@ int syscall_system_rtc( struct rtc_time *time )
return syscall(SYSCALL_SYSTEM_RTC, (uint32_t)time, 0, 0, 0, 0);
}

int syscall_device_driver_stats(char * name, void * stats)
{
return syscall(SYSCALL_DEVICE_DRIVER_STATS, (uint32_t) name, (uint32_t) stats, 0, 0, 0);
}

int syscall_chdir(const char *path)
{
return syscall(SYSCALL_CHDIR, (uint32_t) path, 0, 0, 0, 0);
Expand Down
2 changes: 1 addition & 1 deletion user/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

include ../Makefile.config

USER_PROGRAMS=test.exe long.exe printer.exe forktest.exe errcodes.exe exectest.exe filedescribetest.exe saver.exe ball.exe write.exe shell.exe pipetest.exe snake.exe sysstat.exe procstat.exe writebig.exe manager.exe clock.exe mandelbrot.exe open.exe copy.exe
USER_PROGRAMS=test.exe long.exe printer.exe forktest.exe errcodes.exe exectest.exe filedescribetest.exe saver.exe ball.exe write.exe shell.exe pipetest.exe snake.exe sysstat.exe procstat.exe writebig.exe manager.exe clock.exe mandelbrot.exe open.exe copy.exe livestat.exe statworkload.exe

all: $(USER_PROGRAMS)

Expand Down
Loading

0 comments on commit bf596aa

Please sign in to comment.