Skip to content

Commit

Permalink
Merge branch 'master' into issues/issue7
Browse files Browse the repository at this point in the history
* master:
  mxqd: Limit call rate of killall_over_time() to max. every 5 minutes
  mx_util: Add mx_within_rate_limit_or_return(sec, ret)
  README.md: Add links to sources
  MXQ bump version
  mxqd: Add option --recover-only to exit after recovering from crash
  mx_util: Cleanup mx_strvec_join()
  mx_util: Clean up mx_*cpuset*()
  mx_util: Cleanup mx_malloc_forever()
  mxqd: restrict job to assigned cpuset
  mxqd: assign cpusets to jobs an keep book of running cpus
  mxq_job: expand struct to hold cpuset assigned to job
  mxqd: add and use helper function for cpuset logging
  mxqd: find and store cpu affinitity
  mx_util: Add functions to scan and format cpusets
  mx_util: Add mx_strvec_join()
  mx_util: add mx_malloc_forever
  • Loading branch information
mariux committed Oct 23, 2015
2 parents 83785b5 + 1f1c51a commit a83d32d
Show file tree
Hide file tree
Showing 8 changed files with 349 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MXQ_VERSION_MAJOR = 0
MXQ_VERSION_MINOR = 16
MXQ_VERSION_PATCH = 1
MXQ_VERSION_MINOR = 17
MXQ_VERSION_PATCH = 0
MXQ_VERSION_EXTRA = "beta"
MXQ_VERSIONDATE = 2013-2015

Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# mxq
MXQ - mariux64 job scheduling system

## Sources
### Main git repository

https://github.molgen.mpg.de/mariux64/mxq

### github.com clone

https://github.com/mariux/mxq

## Installation
### Install using `GNU make`
```
Expand Down
160 changes: 160 additions & 0 deletions mx_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <libgen.h>
#include <unistd.h>

#include <ctype.h>

//#include <sys/types.h>
//#include <sys/stat.h>
#include <fcntl.h>
Expand Down Expand Up @@ -553,6 +555,18 @@ int mx_strtoi64(char *str, int64_t *to)
return 0;
}

void *mx_malloc_forever(size_t size)
{
void *ret;

do {
ret = malloc(size);
assert(ret || (!ret && errno == ENOMEM));
} while (!ret);

return ret ;
}

char *mx_strdup_forever(char *str)
{
char *dup;
Expand Down Expand Up @@ -1160,3 +1174,149 @@ char **mx_strvec_from_str(char *str)

return strvec;
}

int mx_str_to_cpuset(cpu_set_t* cpuset_ptr, char *str)
{
char c;
int cpu_low;
int cpu_high;
char *next;
int i;

CPU_ZERO(cpuset_ptr);

while (1) {
c = *str;

if (c == '\0')
break;

if (!isdigit(c))
return -(errno=EINVAL);

cpu_low = strtol(str, &next, 10);
str = next;

if (cpu_low < 0 || cpu_low >= CPU_SETSIZE)
return -(errno=ERANGE);

c = *str;

CPU_SET(cpu_low, cpuset_ptr);

if (c == '\0') {
break;
} else if (c == ',') {
str++;
continue;
} else if (c != '-') {
return -(errno=EINVAL);
}

str++;
c = *str;

if (!isdigit(c))
return -(errno=EINVAL);

cpu_high = strtol(str, &next, 10);
str = next;

if (cpu_high < 0 || cpu_high >= CPU_SETSIZE || cpu_high < cpu_low)
return -(errno=ERANGE);

for (i = cpu_low+1; i <= cpu_high; i++)
CPU_SET(i, cpuset_ptr);

c = *str;

if (c == '\0') {
break;
} else if (c != ',') {
return -(errno=EINVAL);
}

str++;
}
return 0;
}

char *mx_strvec_join(char *sep,char **strvec)
{
int elements=0;
int len=0;
char *out;
char *in;
char *p;
int i;

assert(sep);
assert(strvec);

for (i=0;(in=strvec[i]);i++) {
elements++;
len += strlen(in);
}

if (elements == 0)
return mx_strdup_forever("");

len += strlen(sep)*(elements-1);
out = mx_malloc_forever(len+1);
p = out;

for (i=0;i<elements-1;i++) {
p = stpcpy(p, strvec[i]);
p = stpcpy(p, sep);
}
p = stpcpy(p, strvec[i]);

return out;
}

char *mx_cpuset_to_str(cpu_set_t* cpuset_ptr)
{
char **strvec;
int cpu;
int cpu_low;
int cpu_high;
char *str;
int res;
char *out;

strvec=mx_strvec_new();
if (!strvec)
return NULL;

cpu=0;
while(1) {
if (cpu>=CPU_SETSIZE)
break;

if (CPU_ISSET(cpu,cpuset_ptr)) {
cpu_low=cpu;
while (1) {
cpu++;
if (cpu>=CPU_SETSIZE || !CPU_ISSET(cpu,cpuset_ptr))
break;
}
cpu_high=cpu-1;
if (cpu_low==cpu_high) {
mx_asprintf_forever(&str,"%d",cpu_low);
} else {
mx_asprintf_forever(&str,"%d-%d",cpu_low,cpu_high);
}
res=mx_strvec_push_str(&strvec,str);
if (!res) {
mx_strvec_free(strvec);
return NULL;
}
} else {
cpu++;
}
}

out=mx_strvec_join(",",strvec);
mx_strvec_free(strvec);
return out;
}
20 changes: 20 additions & 0 deletions mx_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
#include <stdarg.h>
#include <string.h>
#include <stdio.h>
#include <sched.h>
#include <unistd.h>
#include <sys/time.h>

#include "mx_log.h"

Expand Down Expand Up @@ -117,6 +120,18 @@ static inline void __mx_fclose(FILE **ptr) {
#undef mx_streq_nocase
#define mx_streq_nocase(a, b) (strcasecmp((a), (b)) == 0)

#define mx_within_rate_limit_or_return(sec, ret) \
do {\
static struct timeval _sleep = {0};\
struct timeval _now;\
struct timeval _delta;\
gettimeofday(&_now, NULL);\
timersub(&_now, &_sleep, &_delta);\
if (_delta.tv_sec < (sec))\
return (ret);\
_sleep = _now;\
} while(0)

int mx_strbeginswith(char *str, const char *start, char **endptr);
int mx_stribeginswith(char *str, const char *start, char **endptr);
int mx_strbeginswithany(char *str, char **starts, char **endptr);
Expand Down Expand Up @@ -146,6 +161,7 @@ int mx_strtoi16(char *str, int16_t *to);
int mx_strtoi32(char *str, int32_t *to);
int mx_strtoi64(char *str, int64_t *to);

void *mx_malloc_forever(size_t size);
char *mx_strdup_forever(char *str);
int mx_vasprintf_forever(char **strp, const char *fmt, va_list ap);
int mx_asprintf_forever(char **strp, const char *fmt, ...) __attribute__ ((format(printf, 2, 3)));
Expand Down Expand Up @@ -189,5 +205,9 @@ int mx_strvec_push_strvec(char*** strvecp, char **strvec);
char* mx_strvec_to_str(char **strvec);
char** mx_strvec_from_str(char *str);
void mx_strvec_free(char **strvec);
char* mx_strvec_join(char *sep,char **strvec);

char* mx_cpuset_to_str(cpu_set_t* cpuset_ptr);
int mx_str_to_cpuset(cpu_set_t* cpuset_ptr,char *str);

#endif
3 changes: 3 additions & 0 deletions mxq_job.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <sys/time.h>
#include <sys/resource.h>

#include <sched.h>

#include "mxq_group.h"

struct mxq_job {
Expand Down Expand Up @@ -42,6 +44,7 @@ struct mxq_job {

uint32_t host_pid;
uint32_t host_slots;
cpu_set_t host_cpu_set;

int64_t date_submit;
int64_t date_start;
Expand Down
Loading

0 comments on commit a83d32d

Please sign in to comment.