Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-who committed Apr 25, 2024
1 parent cffc089 commit d4ecc52
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 38 deletions.
4 changes: 4 additions & 0 deletions spit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ target_link_libraries(dataset m)
add_executable(modcat modcat.c)
#target_link_libraries()

add_executable(fakecluster fakecluster.c fakecluster.h)



add_executable(testdevice testdevice.c utilstime.c utilstime.h utils.c blockdevices.c blockdevices.h keyvalue.c keyvalue.h)
target_link_libraries(testdevice spitlib m aio pthread numa pci uuid)

Expand Down
17 changes: 11 additions & 6 deletions spit/advertise-mc.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ void *advertiseMC(void *arg) {
uname(&buf);


blockDevicesType *bd = blockDevicesInit();

// find unique hw.mac
// interfacesIntType *n = interfacesInit();
Expand All @@ -78,10 +77,19 @@ void *advertiseMC(void *arg) {
double last = 0;
while (keepRunning) {
double now = timeAsDouble();
size_t hddsize = 0, hddnum = 0, ssdsize= 0, ssdnum = 0, volatileramsize = 0, volatileramnum = 0;

if (now - last > 60) { // run first time
// every 60s scan
blockDevicesType *bd = blockDevicesInit();
blockDevicesScan(bd);
hddsize = 0;
hddnum = blockDevicesCount(bd, "HDD", &hddsize);
ssdsize = 0;
ssdnum = blockDevicesCount(bd, "SSD", &ssdsize);
volatileramsize = 0;
volatileramnum = blockDevicesCount(bd, "Volatile-RAM", &volatileramsize);

interfacesIntType *n = interfacesInit();
interfacesScan(n);
free(adv_ip);
Expand Down Expand Up @@ -123,15 +131,12 @@ void *advertiseMC(void *arg) {
keyvalueSetLong(kv, "cluster", cluster->id);
keyvalueSetLong(kv, "port", tc->serverport);

size_t hddsize = 0;
size_t hddnum = blockDevicesCount(bd, "HDD", &hddsize);
size_t ssdsize = 0;
size_t ssdnum = blockDevicesCount(bd, NULL, &ssdsize);

keyvalueSetLong(kv, "HDDcount", hddnum);
keyvalueSetLong(kv, "HDDsizeGB", ceil(hddsize / 1000.0 / 1000 / 1000));
keyvalueSetLong(kv, "SSDcount", ssdnum);
keyvalueSetLong(kv, "SSDsizeGB", ceil(ssdsize / 1000.0 / 1000 / 1000));
keyvalueSetLong(kv, "VolatileRAMcount", volatileramnum);
keyvalueSetLong(kv, "VolatileRAMsizeGB", ceil(volatileramsize / 1000.0 / 1000 / 1000));

keyvalueSetLong(kv, "Cores", getNumHardwareThreads());
keyvalueSetLong(kv, "RAMGB", ceil(totalRAM()/1024.0/1024/1024));
Expand Down
62 changes: 40 additions & 22 deletions spit/blockdevices.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ void blockDevicesScan(blockDevicesType *bd) {
char isr[100];
sprintf(isr,"/sys/block/%s/queue/rotational", suf);


unsigned int major = 0,minor = 0;
majorAndMinor(fd, &major, &minor);
keyvalueSetString(k, "paths", path);
keyvalueSetLong(k, "major", major);
keyvalueSetLong(k, "minor", minor);


int rot = getValueFromFile(isr, 1);

char isremove[100];
Expand All @@ -73,10 +81,17 @@ void blockDevicesScan(blockDevicesType *bd) {
if (canremove) {
keyvalueSetString(k, "type", "Removable");
} else {
if (rot && 0) {
keyvalueSetString(k, "type", "HDD");
} else {
keyvalueSetString(k, "type", "SSD");
if (major == 1) { // ram
keyvalueSetString(k, "type", "Volatile-RAM");
}
if (major == 8) {
if (rot) {
keyvalueSetString(k, "type", "HDD");
} else {
keyvalueSetString(k, "type", "SSD");
}
} else if (major >= 243) {
keyvalueSetString(k, "type", "Virtual");
}
}

Expand Down Expand Up @@ -104,30 +119,31 @@ void blockDevicesScan(blockDevicesType *bd) {
free(suf);


unsigned int major = 0,minor = 0;
majorAndMinor(fd, &major, &minor);
keyvalueSetString(k, "paths", path);
keyvalueSetLong(k, "major", major);
keyvalueSetLong(k, "minor", minor);
if (major == 8) { // HDD

if (major >= 243 || major ==8 || major == 1) {
// valid one to add
char *serial = NULL, *model = NULL, *vendor = NULL, *scsi = NULL;
size_t s = blockDeviceSizeFromFD(fd);
keyvalueSetLong(k, "size", s);
char *serial = serialFromFD(fd);
keyvalueSetString(k, "serial", serial?serial:"n/a");
char *model = modelFromFD(fd);
keyvalueSetString(k, "model", model?model:"n/a");
char *vendor = vendorFromFD(fd);
keyvalueSetString(k, "vendor", vendor?vendor:"n/a");
char *scsi= SCSISerialFromFD(fd);
keyvalueSetString(k, "scsi", scsi?scsi:"n/a");

if (major >= 243) {
}
if (major == 8) { // block

serial = serialFromFD(fd);
keyvalueSetString(k, "serial", serial?serial:"n/a");
model = modelFromFD(fd);
keyvalueSetString(k, "model", model?model:"n/a");
vendor = vendorFromFD(fd);
keyvalueSetString(k, "vendor", vendor?vendor:"n/a");
scsi= SCSISerialFromFD(fd);
keyvalueSetString(k, "scsi", scsi?scsi:"n/a");

}

blockDevicesAddKV(bd, k);

free(serial);
free(model);
free(scsi);

} else {
keyvalueFree(k);
}
Expand Down Expand Up @@ -179,8 +195,10 @@ size_t blockDevicesCount(blockDevicesType *bd, const char *devtype, size_t *sumb
(*sumbytes) = 0;
for (size_t i = 0; i < bd->num; i++) {
char *v = keyvalueGetString(bd->devices[i].kv, "type");
// fprintf(stderr,"checking haystack %s, needle %s\n", devtype, v);
if (v) {
if ((devtype == NULL) || (strcmp(v, devtype) == 0)) {
if ((devtype == NULL) || (strstr(devtype, v) != 0)) {
// fprintf(stderr,"match\n");
matched++;
*sumbytes = (*sumbytes) + keyvalueGetLong(bd->devices[i].kv, "size");
}
Expand Down
17 changes: 11 additions & 6 deletions spit/blockdevicesMain.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,24 @@ int main(int argc, char *argv[]) {
(void)argv;
blockDevicesType *bd = blockDevicesInit();
blockDevicesScan(bd);
blockDevicesScan(bd);
blockDevicesScan(bd);
blockDevicesScan(bd);

for (size_t i = 0; i < bd->num; i++) {
char *s = keyvalueDumpAsString(bd->devices[i].kv);
printf("%s\n", s);
free(s);
}

size_t hddsize = 0;
size_t numHDD = blockDevicesCount(bd, "SSD", &hddsize);
printf("numHDD: %zd, size = %.1lf GB\n", numHDD, hddsize / (double)1000.0 / 1000.0 / 1000.0);
size_t size = 0;
size_t num = blockDevicesCount(bd, "SSD,HDD", &size);
printf("SSD: %zd, size = %.1lf GB\n", num, size / (double)1000.0 / 1000.0 / 1000.0);
num = blockDevicesCount(bd, "HDD", &size);
printf("HDD: %zd, size = %.1lf GB\n", num, size / (double)1000.0 / 1000.0 / 1000.0);
num = blockDevicesCount(bd, "HDD,SDD", &size);
printf("HDD,SSD: %zd, size = %.1lf GB\n", num, size / (double)1000.0 / 1000.0 / 1000.0);
num = blockDevicesCount(bd, "Volatile-RAM", &size);
printf("Volatile-RAM: num: %zd, size = %.1lf GB\n", num, size / (double)1000.0 / 1000.0 / 1000.0);
num = blockDevicesCount(bd, "Virtual", &size);
printf("Virtual: num: %zd, size = %.1lf GB\n", num, size / (double)1000.0 / 1000.0 / 1000.0);

blockDevicesFree(bd);
return 0;
Expand Down
6 changes: 4 additions & 2 deletions spit/cluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,11 @@ char *clusterDumpJSONString(clusterType *c) {
buf += sprintf(buf, " \"RAMGB\": %ld,\n", keyvalueGetLong(c->node[i]->info, "RAMGB"));
buf += sprintf(buf, " \"Cores\": %ld,\n", keyvalueGetLong(c->node[i]->info, "Cores"));
buf += sprintf(buf, " \"HDDcount\": %ld,\n", keyvalueGetLong(c->node[i]->info, "HDDcount"));
buf += sprintf(buf, " \"HDDsizeGB\": %ld,\n", keyvalueGetLong(c->node[i]->info, "HDDSizeGB"));
buf += sprintf(buf, " \"HDDsizeGB\": %ld,\n", keyvalueGetLong(c->node[i]->info, "HDDsizeGB"));
buf += sprintf(buf, " \"SSDcount\": %ld,\n", keyvalueGetLong(c->node[i]->info, "SSDcount"));
buf += sprintf(buf, " \"SSDsizeGB\": %ld\n", keyvalueGetLong(c->node[i]->info, "SSDSizeGB"));
buf += sprintf(buf, " \"SSDsizeGB\": %ld,\n", keyvalueGetLong(c->node[i]->info, "SSDsizeGB"));
buf += sprintf(buf, " \"VolatileRAMcount\": %ld,\n", keyvalueGetLong(c->node[i]->info, "VolatileRAMcount"));
buf += sprintf(buf, " \"VolatileRAMsizeGB\": %ld\n", keyvalueGetLong(c->node[i]->info, "VolatileRAMsizeGB"));

buf += sprintf(buf, " }");
if (i < c->id-1) buf += sprintf(buf, ",");
Expand Down
51 changes: 51 additions & 0 deletions spit/fakecluster.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include <stdio.h>
#include <malloc.h>

#include "fakecluster.h"

fakeclusterType *fakeclusterInit(int size) {
fakeclusterType *c = calloc(size, sizeof(fakeclusterType));

for (int i = 0; i < size; i++ ){
c[i].id = i;
c[i].time = 0;
c[i].RAMGB = 4+(i % 8);
c[i].numGPUs = i%3;
c[i].numDevices = 20+3*i;
c[i].bdSize = (i%2) ? 18000 : 12000;
}

return c;
}

void dumpNode(fakeclusterType *c) {
// cpu
// gpu
// device
// name, size, type, serial, acores, bcores
// d;23 d#0|name:/dev/sda|size:18000|type:SSD|serial:912812| d#1|name...

printf("%d %lf %d %d %d %d\n", c->id, c->time, c->RAMGB, c->numGPUs, c->numDevices, c->bdSize);

}


void fakeclusterDump(fakeclusterType *c, int size) {
for (int i = 0; i < size; i++) {
dumpNode(&c[i]);
}
}


int main(void) {

int size = 100;
fakeclusterType *cluster = fakeclusterInit(size);

fakeclusterDump(cluster, size);

free(cluster);

return 0;
}

16 changes: 16 additions & 0 deletions spit/fakecluster.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef _FAKECLUSTER_H
#define _FAKECLUSTER_H


typedef struct {
int id;
double time;
int RAMGB;
int numGPUs;
int numDevices;
int bdSize;
} fakeclusterType;

fakeclusterType *fakeclusterInit(int size);

#endif
2 changes: 1 addition & 1 deletion spit/keyvalue.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ long keyvalueGetLong(keyvalueType *kv, const char *key) {
char *keyvalueGetString(keyvalueType *kv, const char *key) {
int index = keyvalueFindKey(kv, key);
if (index < 0) {
fprintf(stderr,"can't find: %s\n", key);
// fprintf(stderr,"can't find: %s\n", key);
return NULL;
}
assert(kv->pairs[index].type != 1);
Expand Down
4 changes: 3 additions & 1 deletion spit/respond-mc.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@ void *respondMC(void *arg) {
keyvalueSetLong(tc->cluster->node[nodeid]->info, "HDDcount", keyvalueGetLong(kv, "HDDcount"));
keyvalueSetLong(tc->cluster->node[nodeid]->info, "HDDsizeGB", keyvalueGetLong(kv, "HDDsizeGB"));
keyvalueSetLong(tc->cluster->node[nodeid]->info, "SSDcount", keyvalueGetLong(kv, "SSDcount"));
keyvalueSetLong(tc->cluster->node[nodeid]->info, "SDDsizeGB", keyvalueGetLong(kv, "SSDsizeGB"));
keyvalueSetLong(tc->cluster->node[nodeid]->info, "SSDsizeGB", keyvalueGetLong(kv, "SSDsizeGB"));
keyvalueSetLong(tc->cluster->node[nodeid]->info, "VolatileRAMcount", keyvalueGetLong(kv, "VolatileRAMcount"));
keyvalueSetLong(tc->cluster->node[nodeid]->info, "VolatileRAMsizeGB", keyvalueGetLong(kv, "VolatileRAMsizeGB"));

keyvalueSetLong(tc->cluster->node[nodeid]->info, "RAMGB", keyvalueGetLong(kv, "RAMGB"));
keyvalueSetLong(tc->cluster->node[nodeid]->info, "Cores", keyvalueGetLong(kv, "Cores"));
Expand Down

0 comments on commit d4ecc52

Please sign in to comment.