Permalink
Browse files

[GH #830] Add Parrot_set_num_threads and --numthreads cmdline

The new parrot cmdline option --numthreads overrides Parrot_get_num_cpus().
Parrot_set_num_threads is called by Parrot_interp_initialize_interpreter()
  • Loading branch information...
Reini Urban
Reini Urban committed Sep 16, 2012
1 parent fba6c79 commit b6c1cdaf9e36e006ce5e6841b7a9db8642d9c460
Showing with 28 additions and 4 deletions.
  1. +1 −0 .gitignore
  2. +18 −0 frontend/parrot2/main.c
  3. +1 −0 include/parrot/api.h
  4. +1 −0 include/parrot/gc_api.h
  5. +2 −1 include/parrot/longopt.h
  6. +1 −0 src/embed/api.c
  7. +4 −3 src/interp/api.c
View
@@ -335,6 +335,7 @@ cachegrind.out.*
/src/dynpmc/*.obj
/src/dynpmc/*.pdb
/src/dynpmc/*.so
+/src/dynpmc/*.str
/src/gc/*.o
/src/gc/*.obj
/src/interp/*.o
View
@@ -136,6 +136,7 @@ main(int argc, const char *argv[])
GET_INIT_STRUCT(initargs);
+ initargs->numthreads = 0;
/* Parse minimal subset of flags */
parseflags_minimal(initargs, argc, argv);
@@ -428,6 +429,7 @@ Parrot_cmd_options(void)
{ '\0', OPT_GC_DYNAMIC_THRESHOLD, OPTION_required_FLAG, { "--gc-dynamic-threshold" } },
{ '\0', OPT_GC_MIN_THRESHOLD, OPTION_required_FLAG, { "--gc-min-threshold" } },
{ '\0', OPT_GC_DEBUG, (OPTION_flags)0, { "--gc-debug" } },
+ { '\0', OPT_NUMTHREADS, OPTION_required_FLAG, { "--numthreads" } },
{ 'V', 'V', (OPTION_flags)0, { "--version" } },
{ 'X', 'X', OPTION_required_FLAG, { "--dynext" } },
{ '\0', OPT_DESTROY_FLAG, (OPTION_flags)0,
@@ -512,6 +514,22 @@ parseflags_minimal(ARGMOD(Parrot_Init_Args * initargs), int argc, ARGIN(const ch
}
break;
+ case OPT_NUMTHREADS:
+ if (opt.opt_arg && is_all_digits(opt.opt_arg)) {
+ initargs->numthreads = strtoul(opt.opt_arg, NULL, 8);
+
+ if ( initargs->numthreads < 2 || initargs->numthreads > 1e8 ) {

This comment has been minimized.

Show comment Hide comment
@leto

leto Sep 16, 2012

Owner

Perhaps we should make the maximum number of threads a compile-time option?

@leto

leto Sep 16, 2012

Owner

Perhaps we should make the maximum number of threads a compile-time option?

+ fprintf(stderr, "error: minimum number of threads is 2\n");
+ exit(EXIT_FAILURE);
+ }
+ }
+ else {
+ fprintf(stderr, "error: invalid number of threads specified:"
+ "'%s'\n", opt.opt_arg);
+ exit(EXIT_FAILURE);
+ }
+ break;
+
case OPT_HASH_SEED:
if (opt.opt_arg && is_all_hex_digits(opt.opt_arg)) {
initargs->hash_seed = strtoul(opt.opt_arg, NULL, 16);
View
@@ -77,6 +77,7 @@ typedef struct _Parrot_Init_Args {
Parrot_Int gc_dynamic_threshold;
Parrot_Int gc_min_threshold;
Parrot_UInt hash_seed;
+ Parrot_UInt numthreads;
} Parrot_Init_Args;
#define GET_INIT_STRUCT(i) do {\
View
@@ -39,6 +39,7 @@ typedef struct _Parrot_GC_Init_Args {
Parrot_Float4 nursery_size;
Parrot_Int dynamic_threshold;
Parrot_Int min_threshold;
+ Parrot_UInt numthreads;
} Parrot_GC_Init_Args;
typedef enum _gc_sys_type_enum {
View
@@ -1,5 +1,5 @@
/* longopt.h
- * Copyright (C) 2001-2010, Parrot Foundation.
+ * Copyright (C) 2001-2012, Parrot Foundation.
* Overview:
* Command line option parsing (for pre-initialized code)
*/
@@ -49,6 +49,7 @@ struct longopt_opt_info {
#define OPT_GC_DYNAMIC_THRESHOLD 134
#define OPT_GC_MIN_THRESHOLD 135
#define OPT_GC_NURSERY_SIZE 136
+#define OPT_NUMTHREADS 137
/* HEADERIZER BEGIN: src/longopt.c */
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
View
@@ -143,6 +143,7 @@ Parrot_api_make_interpreter(Parrot_PMC parent, Parrot_Int flags,
gc_args.nursery_size = args->gc_nursery_size;
gc_args.dynamic_threshold = args->gc_dynamic_threshold;
gc_args.min_threshold = args->gc_min_threshold;
+ gc_args.numthreads = args->numthreads;
if (args->hash_seed)
interp_raw->hash_seed = args->hash_seed;
View
@@ -17,7 +17,6 @@ Functions related to managing the Parrot interpreter
*/
-
#include "parrot/parrot.h"
#include "parrot/runcore_api.h"
#include "parrot/oplib/core_ops.h"
@@ -27,6 +26,7 @@ Functions related to managing the Parrot interpreter
#include "pmc/pmc_parrotinterpreter.h"
#include "parrot/has_header.h"
#include "imcc/embed.h"
+#include "parrot/thread.h"
#ifdef PARROT_HAS_HEADER_SYSUTSNAME
# include <sys/utsname.h>
@@ -319,8 +319,9 @@ Parrot_interp_initialize_interpreter(PARROT_INTERP, ARGIN(Parrot_GC_Init_Args *a
/* setup stdio PMCs */
Parrot_io_init(interp);
- /* all sys running, init the event and signal stuff */
-
+ /* all sys running, init the threads, event and signal stuff */
+ if (args->numthreads)
+ Parrot_set_num_threads(interp, args->numthreads);
Parrot_cx_init_scheduler(interp);
#ifdef PARROT_HAS_THREADS

0 comments on commit b6c1cda

Please sign in to comment.