Skip to content

Livestat: A User Tool to dynamically display basekernel stats #252

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

Merged
merged 47 commits into from
Sep 6, 2019
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
30f5e17
changed the head command
jmazanec15 Jan 18, 2019
bd243da
changed the head num to 20001
jmazanec15 Jan 18, 2019
00bb845
Merge branch 'master' of github.com:dthain/basekernel
jmazanec15 Jan 25, 2019
9369ef8
Merge branch 'master' of github.com:dthain/basekernel
jmazanec15 Jan 28, 2019
57bc375
added bcache stats
jmazanec15 Jan 30, 2019
28e969d
added syscall for bcache stats
jmazanec15 Jan 30, 2019
4c0b8dd
added bcache stats test
jmazanec15 Jan 30, 2019
e71824e
added syscall for bcache stats
jmazanec15 Jan 30, 2019
fca3ebd
move bcache stats struct to stats.h
jmazanec15 Jan 30, 2019
1e237ed
Merge branch 'master' of github.com:dthain/basekernel into stats-collect
jmazanec15 Feb 11, 2019
a9e0ff8
added bcache_flush syscall
jmazanec15 Feb 12, 2019
5ead44f
added get stats for objects
jmazanec15 Feb 12, 2019
87ee455
added stats collection
jmazanec15 Apr 3, 2019
5440ecb
added driver and object stats collection
jmazanec15 Apr 3, 2019
044424a
fixed syntax
jmazanec15 Apr 3, 2019
d8911ae
added calls for stats collection
jmazanec15 Apr 3, 2019
6b73a2a
added dev driver stats to enum
jmazanec15 Apr 3, 2019
42c7222
added stats
jmazanec15 Apr 9, 2019
f290dec
added stats
jmazanec15 Apr 9, 2019
e2bf8d3
added stats
jmazanec15 Apr 9, 2019
2c01ed5
added strdup
jmazanec15 Apr 9, 2019
7e40b4b
init commit
jmazanec15 Apr 24, 2019
b5e6802
remove bcachetest
jmazanec15 Apr 24, 2019
fcfabed
added livestat and statworkload
jmazanec15 Apr 24, 2019
74f485e
added stats collection
jmazanec15 Apr 24, 2019
9af87c5
added strdup
jmazanec15 Apr 24, 2019
308a6e1
added more stats structs
jmazanec15 Apr 24, 2019
b90b8f3
added stats collection calls
jmazanec15 Apr 24, 2019
ff4098f
removed objectstats
jmazanec15 Apr 24, 2019
2eb5607
removed object stats
jmazanec15 Apr 24, 2019
fb7dee8
removed structs related to object syscalls
jmazanec15 Apr 24, 2019
6c6f680
Revert "added stats"
jmazanec15 Apr 24, 2019
29bb3b2
Revert "added stats"
jmazanec15 Apr 24, 2019
df71c42
removed the device statistics
jmazanec15 Apr 24, 2019
318af72
Revert "added stats collection"
jmazanec15 Apr 24, 2019
b42fd66
removed object stats functions
jmazanec15 Apr 24, 2019
26e7110
Revert "added get stats for objects"
jmazanec15 Apr 24, 2019
bc72194
changed bar graphs
jmazanec15 Apr 24, 2019
cbc9980
minor comment changes
jmazanec15 Apr 24, 2019
a161fc3
removed ata include, added stats include
jmazanec15 Apr 24, 2019
bf9398d
added device_driver_lookup funct
jmazanec15 May 9, 2019
7b45303
modified driver stats to take in const char * name
jmazanec15 May 9, 2019
c53ad89
added pointer and string checking to driver stats
jmazanec15 May 9, 2019
506c42e
Merge branch 'master' of github.com:dthain/basekernel into livestat
jmazanec15 May 9, 2019
d844bbc
fixed redefinition error from merge
jmazanec15 May 9, 2019
f3ff93c
fixed strdup function
jmazanec15 May 9, 2019
25949c9
pass args by pointers
jmazanec15 May 9, 2019
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
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 @@ -13,6 +13,7 @@ void strcpy(char *d, const char *s);
void strncpy(char *d, const char *s, unsigned length);
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
39 changes: 35 additions & 4 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 @@ -99,26 +100,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 +159,18 @@ const char * device_name( struct device *d )
{
return d->driver->name;
}

void device_driver_get_stats(char * name, struct device_driver_stats * s)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please factor out the matter of finding a driver by name into a separate function:

struct device_driver * device_driver_lookup( const char *name )

And then also use that in driver_open.

{
/* Look up driver of the given name */
struct device_driver *dd = driver_list;
for(dd=driver_list; dd; dd=dd->next) {
if(!strcmp(dd->name, name)) {
break;
}
}

if (dd) {
memcpy(s, &(dd->stats), sizeof(*s));
}
}
4 changes: 4 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,6 @@ int device_nblocks( struct device *d );
int device_unit( struct device *d );
const char * device_name( struct device *d );

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

#endif
34 changes: 26 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 @@ -568,6 +564,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 @@ -584,6 +593,12 @@ int sys_system_rtc( struct rtc_time *t )
return 0;
}

int sys_device_driver_stats(char * name, struct device_driver_stats * stats)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const char *name and is_valid_string(name)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is_valid_pointer(stats)

{
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 @@ -665,8 +680,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 @@ -681,11 +694,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
9 changes: 9 additions & 0 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 "stdarg.h"

Expand Down Expand Up @@ -59,6 +60,14 @@ int strncmp(const char *a, const char *b, unsigned length)
return 0;
}

char *strdup(const char *s)
{
char *new = malloc(strlen(s) + 1);
if(new)
strcpy(new, s);
return new;
}

unsigned strlen(const char *s)
{
unsigned len = 0;
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