Skip to content

Commit

Permalink
OS-5738 increase timers allowed per-process
Browse files Browse the repository at this point in the history
Reviewed by: Ryan Zezeski <rpz@joyent.com>
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Approved by: Jerry Jelinek <jerry.jelinek@joyent.com>
  • Loading branch information
pfmooney committed Nov 16, 2016
1 parent 289e41b commit b103d86
Show file tree
Hide file tree
Showing 9 changed files with 292 additions and 52 deletions.
4 changes: 4 additions & 0 deletions usr/src/test/os-tests/runfiles/default.run
Expand Up @@ -48,6 +48,10 @@ tests = ['sigqueue_queue_size']
user = root
tests = ['sdevfs_eisdir']

[/opt/os-tests/tests/timer]
user = root
tests = ['timer_limit']

[/opt/os-tests/tests/tmpfs]
user = root
tests = ['tmpfs_badmount', 'tmpfs_enospc']
Expand Down
2 changes: 1 addition & 1 deletion usr/src/test/os-tests/tests/Makefile
Expand Up @@ -14,6 +14,6 @@
# Copyright 2016 Joyent, Inc.
#

SUBDIRS = poll secflags sigqueue spoof-ras sdevfs tmpfs file-locking
SUBDIRS = poll secflags sigqueue spoof-ras sdevfs timer tmpfs file-locking

include $(SRC)/test/Makefile.com
50 changes: 50 additions & 0 deletions usr/src/test/os-tests/tests/timer/Makefile
@@ -0,0 +1,50 @@
#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source. A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#

#
# Copyright 2016 Joyent, Inc.
#

include $(SRC)/Makefile.master

ROOTOPTPKG = $(ROOT)/opt/os-tests
TESTDIR = $(ROOTOPTPKG)/tests/timer

PROGS = timer_limit

include $(SRC)/cmd/Makefile.cmd
include $(SRC)/test/Makefile.com

C99MODE = -xc99=%all


CMDS = $(PROGS:%=$(TESTDIR)/%)
$(CMDS) := FILEMODE = 0555

all: $(PROGS)

install: all $(CMDS)

lint:

clobber: clean
-$(RM) $(PROGS)

clean:
-$(RM) *.o

$(CMDS): $(TESTDIR) $(PROGS)

$(TESTDIR):
$(INS.dir)

$(TESTDIR)/%: %
$(INS.file)
83 changes: 83 additions & 0 deletions usr/src/test/os-tests/tests/timer/timer_limit.c
@@ -0,0 +1,83 @@
/*
* This file and its contents are supplied under the terms of the
* Common Development and Distribution License ("CDDL"), version 1.0.
* You may only use this file in accordance with the terms of version
* 1.0 of the CDDL.
*
* A full copy of the text of the CDDL should have accompanied this
* source. A copy of the CDDL is also available via the Internet at
* http://www.illumos.org/license/CDDL.
*/

/*
* Copyright 2016 Joyent, Inc.
*/


#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <time.h>
#include <limits.h>
#include <assert.h>
#include <sys/sysconfig.h>
#include <sys/sysmacros.h>

/* Need direct access to _sysconfig to query NCPU */
extern long _sysconfig(int);


static int
mktimer(timer_t *timer)
{
struct sigevent sev;
sev.sigev_notify = SIGEV_SIGNAL;
sev.sigev_signo = SIGRTMIN;
sev.sigev_value.sival_ptr = timer;

return (timer_create(CLOCK_MONOTONIC, &sev, timer));
}

int
main()
{
long ncpu;
size_t limit;
timer_t *timers, timer_overage;

/* Query NCPU with private sysconfig param */
ncpu = _sysconfig(_CONFIG_NPROC_NCPU);
assert(ncpu > 0 && ncpu < INT32_MAX);

/* Current specified limit is 4 * NCPU */
limit = 4 * ncpu;
timers = calloc(limit + 1, sizeof (timer_t));
assert(timers != NULL);

/* Slowly walk up to the limit doing creations/deletions */
for (int i = 1; i <= limit; i = MIN(limit, i*2)) {
for (int j = 0; j < i; j++) {
assert(mktimer(&timers[j]) == 0);
}

/*
* Attempt to allocate one additional timer if we've reached
* the assumed limit.
*/
if (i == limit) {
assert(mktimer(&timer_overage) == -1);
}

for (int j = 0; j < i; j++) {
assert(timer_delete(timers[j]) == 0);
}

/* Bail out if we've finished at the limit */
if (i == limit)
break;
}


return (0);
}

0 comments on commit b103d86

Please sign in to comment.