Пример #1
0
void *thread_cli_fun(void *arg) {
    double          busy;
    int             inx;
    Msg            *msg;
    struct rusage   r_start;
    struct rusage   r_stop;
    struct timeval  t_elapsed_data;
    struct timeval  t_elapsed_total;
    struct timeval  t_start_data;
    struct timeval  t_start_total;
    struct timeval  t_stop;

    arg = arg; // touch
    util_time_timer_start(&t_start_total);
    util_time_timer_start(&t_start_data);
    util_cpu_timer_start(&r_start);
    for (inx = 0; inx < loop; inx++) {
        if (verbose)
            printf("count=%d\n", inx);
        msg = msg_queue_remove(&mutex_pool, &queue_pool);
        assert(msg != NULL);
        if (csize) {
            msg->cbuf = (char *) malloc(csize);
            memcpy(msg->cbuf, send_buffer2, csize);
        }
        if (dsize) {
            msg->dbuf = (char *) malloc(dsize);
            memcpy(msg->dbuf, send_buffer, dsize);
        }
        msg_queue_add(&mutex_srv, &queue_srv, msg);
        cv_signal(&cv_srv);
        cv_wait(&cv_cli);
        msg = msg_queue_remove(&mutex_cli, &queue_cli);
        assert(msg != NULL);
        msg_queue_add(&mutex_pool, &queue_pool, msg);
    }
    util_cpu_timer_stop(&r_stop);
    util_time_timer_stop(&t_stop);
    util_time_elapsed(&t_start_total, &t_stop, &t_elapsed_total);
    util_time_elapsed(&t_start_data, &t_stop, &t_elapsed_data);
    util_cpu_timer_busy(&r_start, &r_stop, &t_elapsed_data, &busy);

    if (!bm) {
        print_elapsed("", &t_elapsed_total);
        print_elapsed(" (data)", &t_elapsed_data);
    }
    print_rate(bm, "", bidir ? 2 * loop : loop, dsize, &t_elapsed_data, busy);
    return NULL;
}
Пример #2
0
int main(int argc, char *argv[]) {
    int             arg;
    bool            bm = false;
    char           *buf;
    double          busy;
    bool            chook = false;
    bool            client = false;
    char            errnobuf[100];
    char            error_txt[200];
    int             event_len;
    char            event_data[MS_MON_MAX_SYNC_DATA];
    int             ferr;
    int             inx;
    int             key;
    int             lerr;
    int             loop = 10;
    int             msid;
    int             pid;
    char            prog[MS_MON_MAX_PROCESS_PATH];
    struct rusage   r_start;
    struct rusage   r_stop;
    const char     *server_name = "$SRV";
    int             server_nid;
    TPT_DECL       (server_phandle);
    int             server_pid;
    bool            shook = false;
    struct timeval  t_elapsed;
    struct timeval  t_start;
    struct timeval  t_stop;
    TAD             zargs[] = {
      { "-bm",        TA_Bool, TA_NOMAX,    &bm        },
      { "-chook",     TA_Bool, TA_NOMAX,    &chook     },
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "-shook",     TA_Bool, TA_NOMAX,    &shook     },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

    ferr = msg_init(&argc, &argv);
    arg_proc_args(zargs, false, argc, argv);
    if (chook && client)
        test_debug_hook("c", "c");
    if (shook && !client)
        test_debug_hook("s", "s");
    util_test_start(client);
    ferr = msg_mon_process_startup(!client);  // system messages?
    TEST_CHK_FEOK(ferr);
    proc_enable_external_wakeups();  // allow external wakeups
    if (client) {
        ferr = msg_mon_get_process_info(NULL, &server_nid, &server_pid);
        TEST_CHK_FEOK(ferr);
        sprintf(prog, "%s/%s", getenv("PWD"), argv[0]);
        for (arg = 0; arg < argc; arg++)
            if (strcmp(argv[arg], "-client") == 0) // start_process
                argv[arg] = (char *) "-server";
        ferr = msg_mon_start_process(prog,                   // prog
                                     (char *) server_name,   // name
                                     NULL,                   // ret name
                                     argc,
                                     argv,
                                     TPT_REF(server_phandle),
                                     0,                      // open
                                     NULL,                   // oid
                                     MS_ProcessType_Generic, // type
                                     0,                      // priority
                                     0,                      // debug
                                     0,                      // backup
                                     &server_nid,            // nid
                                     &server_pid,            // pid
                                     NULL,                   // infile
                                     NULL);                  // outfile
        printf("process started, err=%d\n", ferr);
        TEST_CHK_FEOK(ferr);
    }
    util_gethostname(my_name, sizeof(my_name));
    lerr = XWAIT(LREQ, -1); // remove first LREQ
    assert(lerr == LREQ);
    ferr = msg_mon_get_my_segid(&key);
    TEST_CHK_FEOK(ferr);
    // process-wait for client/server/shell
    ferr = msfs_util_wait_process_count(MS_ProcessType_Generic, 3, NULL, false);
    TEST_CHK_FEOK(ferr);
    if (client) {
        ferr = msg_mon_event_wait(1, &event_len, event_data);
        TEST_CHK_FEOK(ferr);
        msid = shmget(key, sizeof(recv_buffer), 0640);
        if (msid == -1) {
            perror("client shmget");
            sprintf(error_txt, "client shmget(%d)=%s\n",
                    key,
                    strerror_r(errno, errnobuf, sizeof(errnobuf)));
        }
        assert(msid != -1);
        buf = (char *) shmat(msid, NULL, 0);
        assert(buf != NULL);
    } else {
        msid = shmget(key, sizeof(recv_buffer), IPC_CREAT | 0640);
        if (msid == -1) {
            perror("server shmget");
            sprintf(error_txt, "server shmget(%d)=%s\n",
                    key,
                    strerror_r(errno, errnobuf, sizeof(errnobuf)));
        }
        assert(msid != -1);
        buf = (char *) shmat(msid, NULL, 0);
        assert(buf != NULL);
        ferr =
          msg_mon_event_send(-1,                         // nid
                             -1,                         // pid
                             MS_ProcessType_Undefined,   // process-type
                             1,                          // event-id
                             0,                          // event-len
                             NULL);                      // event-data
        TEST_CHK_FEOK(ferr);
        ferr = msg_mon_event_wait(1, &event_len, event_data);
        TEST_CHK_FEOK(ferr);
    }

    util_time_timer_start(&t_start);
    util_cpu_timer_start(&r_start);
    if (client) {
        pid = server_pid;
        for (inx = 0; inx < loop; inx++) {
            lerr = XPROCESS_AWAKE_(pid, LREQ);
            assert(lerr == XZFIL_ERR_OK);
            lerr = XWAIT(LDONE, -1);
            assert(lerr == LDONE);
        }
    } else {
        ferr = msg_mon_get_process_info((char *) "$CLI", &server_nid, &pid);
        TEST_CHK_FEOK(ferr);
        for (inx = 0; inx < loop; inx++) {
            lerr = XWAIT(LREQ, -1);
            assert(lerr == LREQ);
            lerr = XPROCESS_AWAKE_(pid, LDONE);
            assert(lerr == XZFIL_ERR_OK);
        }
    }
    util_cpu_timer_stop(&r_stop);
    util_time_timer_stop(&t_stop);
    util_time_elapsed(&t_start, &t_stop, &t_elapsed);
    util_cpu_timer_busy(&r_start, &r_stop, &t_elapsed, &busy);

    if (client) {
        if (!bm)
            print_elapsed("", &t_elapsed);
        print_rate(bm, "", loop, 1024, &t_elapsed, busy);
    } else
        print_server_busy(bm, "", busy);

    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
Пример #3
0
int main(int argc, char *argv[]) {
    bool            bidir = false;
    bool            bm = false;
    void           *buf;
    double          busy;
    _xcc_status     cc;
    int             count_read;
    int             count_written;
    int             count_xferred;
    int             dsize = 1024;
    int             ferr;
    short           filenum[MAX_SERVERS];
    short           filenumr;
    int             inx;
    int             loop = 10;
    int             max;
    int             maxsp = 1;
    bool            mq = false;
    bool            nocopy = false;
    bool            nowaitc = false;
    bool            nowaits = false;
    int             pinx;
    struct rusage   r_start;
    struct rusage   r_stop;
    char           *recv_buffer_ptr;
    RI_Type         ri;
    short           sender_len;
    int             sys_msg;
    struct timeval  t_elapsed_data;
    struct timeval  t_elapsed_open;
    struct timeval  t_elapsed_total;
    struct timeval  t_start_data;
    struct timeval  t_start_total;
    struct timeval  t_stop;
    SB_Tag_Type     tag;
    short           tfilenum;
    int             timeout = -1;
    bool            verbose = false;
    TAD             zargs[] = {
      { "-bidir",     TA_Bool, TA_NOMAX,    &bidir        },
      { "-bm",        TA_Bool, TA_NOMAX,    &bm           },
      { "-client",    TA_Bool, TA_NOMAX,    &client       },
      { "-dsize",     TA_Int,  MAX_DBUF,    &dsize        },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop         },
      { "-maxcp",     TA_Int,  MAX_CLIENTS, &maxcp        },
      { "-maxsp",     TA_Int,  MAX_SERVERS, &maxsp        },
      { "-mq",        TA_Bool, TA_NOMAX,    &mq           },
      { "-nocopy",    TA_Bool, TA_NOMAX,    &nocopy       },
      { "-nowaitc",   TA_Bool, TA_NOMAX,    &nowaitc      },
      { "-nowaits",   TA_Bool, TA_NOMAX,    &nowaits      },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL          },
      { "",           TA_End,  TA_NOMAX,    NULL          }
    };

    for (inx = 0; inx < MAX_CLIENTS; inx++)
        account[inx] = 0;
    signal(SIGUSR2, printaccount);
    ferr = file_init(&argc, &argv);
    TEST_CHK_FEOK(ferr);
    msfs_util_init_fs(&argc, &argv, file_debug_hook);
    arg_proc_args(zargs, false, argc, argv);
    if (maxcp < 0)
        maxcp = 1;
    if (maxsp < 0)
        maxsp = 1;
    util_test_start(client);
    ferr = file_mon_process_startup(!client);  // system messages?
    TEST_CHK_FEOK(ferr);
    if (nocopy) {
        ferr = file_buf_register(buf_alloc, buf_free);
        TEST_CHK_FEOK(ferr);
    }
    ferr = msg_mon_get_my_process_name(my_name, BUFSIZ);
    TEST_CHK_FEOK(ferr);

    // process-wait for clients/servers/shell
    ferr = msfs_util_wait_process_count(MS_ProcessType_Generic,
                                        maxcp + maxsp + 1,
                                        NULL,
                                        verbose);
    if (client)
        sleep(1);
    util_time_timer_start(&t_start_total);
    if (client) {
        inx = atoi(&my_name[4]);
        printf("dsize=%d, loop=%d\n", dsize, loop);
        for (pinx = 0; pinx < maxsp; pinx++) {
            sprintf(serv, "$srv%d", pinx);
            ferr = BFILE_OPEN_(serv, (short) strlen(serv), &filenum[pinx],
                               0, 0, nowaitc ? (short) 1 : (short) 0,
                               0, 0, 0, 0, NULL);
            TEST_CHK_FEOK(ferr);
        }
        util_time_timer_start(&t_start_data);
        util_cpu_timer_start(&r_start);
        util_time_elapsed(&t_start_total, &t_start_data, &t_elapsed_open);
        max = loop;
        for (inx = 0; inx < max; inx++) {
            for (pinx = 0; pinx < maxsp; pinx++) {
                if (pinx == 0) {
                    if (verbose)
                        printf("%s-count=%d\n", my_name, inx);
                    else if (mq && ((inx % 1000) == 0))
                        printf("%s-count=%d\n", my_name, inx);
                }
                cc = BWRITEREADX(filenum[pinx],
                                 send_buffer,
                                 (int) dsize, // cast
                                 bidir ? dsize : 0,
                                 &count_read,
                                 0);
            }
            for (pinx = 0; pinx < maxsp; pinx++) {
                if (nowaitc) {
                    TEST_CHK_CCEQ(cc);
                    tfilenum = filenum[pinx];
                    cc = BAWAITIOX(&tfilenum,
                                   &buf,
                                   &count_xferred,
                                   &tag,
                                   timeout,
                                   NULL);
                    TEST_CHK_CCEQ(cc);
                }
            }
        }
    } else {
        ferr = BFILE_OPEN_((char *) "$RECEIVE", 8, &filenumr,
                           0, 0, nowaits ? (short) 1 : (short) 0, // nowait
                           1, 0, // sys msg
                           0, 0, NULL);
        TEST_CHK_FEOK(ferr);
        util_time_timer_start(&t_start_data);
        util_cpu_timer_start(&r_start);
        max = maxcp * loop;
        for (inx = 0; inx < max; inx++) {
            if (nocopy) {
                cc = file_buf_readupdatex(filenumr,
                                          &recv_buffer_ptr,
                                          &count_read,
                                          0);
                buf_free(recv_buffer_ptr);
            } else
                cc = BREADUPDATEX(filenumr,
                                  recv_buffer,
                                  (int) dsize, // cast
                                  &count_read,
                                  0);
            if (nowaits) {
                tfilenum = -1;
                cc = BAWAITIOX(&tfilenum,
                               &buf,
                               &count_xferred,
                               &tag,
                               timeout,
                               NULL);
                // don't check cc - could be sys msg
                sys_msg = _xstatus_ne(cc);
            } else
                sys_msg = _xstatus_ne(cc);
            if (sys_msg)
                inx--;
            if (!sys_msg) {
                getri(&ri);
                ferr = XPROCESSHANDLE_DECOMPOSE_(TPT_REF(ri.sender),
                                                 NULL, // cpu
                                                 NULL, // pin
                                                 NULL, // nodenumber
                                                 NULL, // nodename
                                                 0,    // nodename
                                                 NULL, // nodename_length
                                                 sender,
                                                 sizeof(sender),
                                                 &sender_len,
                                                 NULL); // sequence_number
                TEST_CHK_FEOK(ferr);
                sender[sender_len] = 0;
                if (verbose)
                    printf("sender=%s\n", sender);
                char *p = &sender[4]; // past $cli
                int sender_inx = atoi(p);
                account[sender_inx]++;
            }
            cc = BREPLYX(recv_buffer,
                         bidir ? dsize : 0,
                         &count_written,
                         0,
                         XZFIL_ERR_OK);
            TEST_CHK_CCEQ(cc);
        }
    }

    util_cpu_timer_stop(&r_stop);
    util_time_timer_stop(&t_stop);
    util_time_elapsed(&t_start_total, &t_stop, &t_elapsed_total);
    util_time_elapsed(&t_start_data, &t_stop, &t_elapsed_data);
    util_cpu_timer_busy(&r_start, &r_stop, &t_elapsed_data, &busy);

    if (client) {
        if (!bm) {
            print_elapsed("", &t_elapsed_total);
            print_elapsed(" (data)", &t_elapsed_data);
            print_elapsed(" (open)", &t_elapsed_open);
        }
        print_rate(bm, "", bidir ? 2 * loop : loop, dsize, &t_elapsed_data, busy);
    } else
        print_server_busy(bm, "", busy);

    if (client) {
        for (pinx = 0; pinx < maxsp; pinx++) {
            ferr = BFILE_CLOSE_(filenum[pinx], 0);
            TEST_CHK_FEOK(ferr);
        }
    } else {
        ferr = BFILE_CLOSE_(filenumr, 0);
        TEST_CHK_FEOK(ferr);
        ferr = file_mon_process_close();
        TEST_CHK_FEOK(ferr);
    }

    ferr = file_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    printaccount(0);
    return 0;
}