lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 | /* Copyright (C) 2002-2015 Free Software Foundation, Inc. |
| 2 | This file is part of the GNU C Library. |
| 3 | Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. |
| 4 | |
| 5 | The GNU C Library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Lesser General Public |
| 7 | License as published by the Free Software Foundation; either |
| 8 | version 2.1 of the License, or (at your option) any later version. |
| 9 | |
| 10 | The GNU C Library is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | Lesser General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Lesser General Public |
| 16 | License along with the GNU C Library; if not, see |
| 17 | <http://www.gnu.org/licenses/>. */ |
| 18 | |
| 19 | #include <argp.h> |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | #define OPT_TO_THREAD 300 |
| 25 | #define OPT_TO_PROCESS 301 |
| 26 | #define OPT_SYNC_SIGNAL 302 |
| 27 | #define OPT_SYNC_JOIN 303 |
| 28 | #define OPT_TOPLEVEL 304 |
| 29 | |
| 30 | |
| 31 | static const struct argp_option test_options[] = |
| 32 | { |
| 33 | { NULL, 0, NULL, 0, "\ |
| 34 | This is a test for threads so we allow ther user to selection the number of \ |
| 35 | threads which are used at any one time. Independently the total number of \ |
| 36 | rounds can be selected. This is the total number of threads which will have \ |
| 37 | run when the process terminates:" }, |
| 38 | { "threads", 't', "NUMBER", 0, "Number of threads used at once" }, |
| 39 | { "starts", 's', "NUMBER", 0, "Total number of working threads" }, |
| 40 | { "toplevel", OPT_TOPLEVEL, "NUMBER", 0, |
| 41 | "Number of toplevel threads which start the other threads; this \ |
| 42 | implies --sync-join" }, |
| 43 | |
| 44 | { NULL, 0, NULL, 0, "\ |
| 45 | Each thread can do one of two things: sleep or do work. The latter is 100% \ |
| 46 | CPU bound. The work load is the probability a thread does work. All values \ |
| 47 | from zero to 100 (inclusive) are valid. How often each thread repeats this \ |
| 48 | can be determined by the number of rounds. The work cost determines how long \ |
| 49 | each work session (not sleeping) takes. If it is zero a thread would \ |
| 50 | effectively nothing. By setting the number of rounds to zero the thread \ |
| 51 | does no work at all and pure thread creation times can be measured." }, |
| 52 | { "workload", 'w', "PERCENT", 0, "Percentage of time spent working" }, |
| 53 | { "workcost", 'c', "NUMBER", 0, |
| 54 | "Factor in the cost of each round of working" }, |
| 55 | { "rounds", 'r', "NUMBER", 0, "Number of rounds each thread runs" }, |
| 56 | |
| 57 | { NULL, 0, NULL, 0, "\ |
| 58 | There are a number of different methods how thread creation can be \ |
| 59 | synchronized. Synchronization is necessary since the number of concurrently \ |
| 60 | running threads is limited." }, |
| 61 | { "sync-signal", OPT_SYNC_SIGNAL, NULL, 0, |
| 62 | "Synchronize using a signal (default)" }, |
| 63 | { "sync-join", OPT_SYNC_JOIN, NULL, 0, "Synchronize using pthread_join" }, |
| 64 | |
| 65 | { NULL, 0, NULL, 0, "\ |
| 66 | One parameter for each threads execution is the size of the stack. If this \ |
| 67 | parameter is not used the system's default stack size is used. If many \ |
| 68 | threads are used the stack size should be chosen quite small." }, |
| 69 | { "stacksize", 'S', "BYTES", 0, "Size of threads stack" }, |
| 70 | { "guardsize", 'g', "BYTES", 0, |
| 71 | "Size of stack guard area; must fit into the stack" }, |
| 72 | |
| 73 | { NULL, 0, NULL, 0, "Signal options:" }, |
| 74 | { "to-thread", OPT_TO_THREAD, NULL, 0, "Send signal to main thread" }, |
| 75 | { "to-process", OPT_TO_PROCESS, NULL, 0, |
| 76 | "Send signal to process (default)" }, |
| 77 | |
| 78 | { NULL, 0, NULL, 0, "Administrative options:" }, |
| 79 | { "progress", 'p', NULL, 0, "Show signs of progress" }, |
| 80 | { "timing", 'T', NULL, 0, |
| 81 | "Measure time from startup to the last thread finishing" }, |
| 82 | { NULL, 0, NULL, 0, NULL } |
| 83 | }; |
| 84 | |
| 85 | /* Prototype for option handler. */ |
| 86 | static error_t parse_opt (int key, char *arg, struct argp_state *state); |
| 87 | |
| 88 | /* Data structure to communicate with argp functions. */ |
| 89 | static struct argp argp = |
| 90 | { |
| 91 | test_options, parse_opt |
| 92 | }; |
| 93 | |
| 94 | |
| 95 | static int |
| 96 | do_test (void) |
| 97 | { |
| 98 | int argc = 2; |
| 99 | char *argv[3] = { (char *) "tst-argp1", (char *) "--help", NULL }; |
| 100 | int remaining; |
| 101 | |
| 102 | /* Parse and process arguments. */ |
| 103 | argp_parse (&argp, argc, argv, 0, &remaining, NULL); |
| 104 | |
| 105 | return 0; |
| 106 | } |
| 107 | |
| 108 | |
| 109 | /* Handle program arguments. */ |
| 110 | static error_t |
| 111 | parse_opt (int key, char *arg, struct argp_state *state) |
| 112 | { |
| 113 | return ARGP_ERR_UNKNOWN; |
| 114 | } |
| 115 | |
| 116 | #define TEST_FUNCTION do_test () |
| 117 | #include "../test-skeleton.c" |