X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Futils%2Floadgen.c;h=fbc145ee1b5690e446d1ad1f4aaf545700dc5f25;hb=3f4ca2cb52dc9c88c8061d8b907b6f793d604f6c;hp=0df9ae34d4a117cb53c30616f4341e2bea5bc6c5;hpb=9848b3e1817ada53dd8a21468692b9be2e10058a;p=fs%2Flustre-release.git diff --git a/lustre/utils/loadgen.c b/lustre/utils/loadgen.c index 0df9ae3..fbc145e 100644 --- a/lustre/utils/loadgen.c +++ b/lustre/utils/loadgen.c @@ -1,6 +1,4 @@ -/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- - * vim:expandtab:shiftwidth=8:tabstop=8: - * +/* * GPL HEADER START * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. @@ -26,8 +24,10 @@ * GPL HEADER END */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved + * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. + * + * Copyright (c) 2013, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -59,12 +59,12 @@ #include #include +#include #include "obdctl.h" static char cmdname[512]; static char target[64] = ""; char nid[64] = ""; -static int live_threads = 0; static int sig_received = 0; static int o_verbose = 4; /* 0-5 */ static int my_oss = 0; @@ -78,7 +78,7 @@ static int jt_quit(int argc, char **argv) { static int loadgen_usage(int argc, char **argv) { if (argc == 1) { - fprintf(stderr, + fprintf(stderr, "This is a test program used to simulate large numbers of\n" "clients. The echo obds are used, so the obdecho module must\n" "be loaded.\n" @@ -145,7 +145,9 @@ struct kid_t { int k_dev; }; +static int live_threads = 0; static struct kid_t *kid_list = NULL; +pthread_mutex_t m_list = PTHREAD_MUTEX_INITIALIZER; static struct kid_t *push_kid(int tnum) { @@ -156,10 +158,12 @@ static struct kid_t *push_kid(int tnum) return NULL; } kid->k_pthread = pthread_self(); + pthread_mutex_lock(&m_list); kid->k_next = kid_list; kid->k_id = tnum; kid_list = kid; live_threads++; + pthread_mutex_unlock(&m_list); return kid; } @@ -470,18 +474,18 @@ out: /* See jt_obd_create */ static int obj_create(struct kid_t *kid) { - struct obd_ioctl_data data; - int rc; - - memset(&data, 0, sizeof(data)); - data.ioc_dev = kid->k_dev; - data.ioc_obdo1.o_mode = 0100644; - data.ioc_obdo1.o_id = 0; - data.ioc_obdo1.o_gr = 2; - data.ioc_obdo1.o_uid = 0; - data.ioc_obdo1.o_gid = 0; - data.ioc_obdo1.o_valid = OBD_MD_FLTYPE | OBD_MD_FLMODE | - OBD_MD_FLID | OBD_MD_FLUID | OBD_MD_FLGID; + struct obd_ioctl_data data; + int rc; + + memset(&data, 0, sizeof(data)); + data.ioc_dev = kid->k_dev; + data.ioc_obdo1.o_mode = 0100644; + ostid_set_seq_echo(&data.ioc_obdo1.o_oi); + ostid_set_id(&data.ioc_obdo1.o_oi, 1); + data.ioc_obdo1.o_uid = 0; + data.ioc_obdo1.o_gid = 0; + data.ioc_obdo1.o_valid = OBD_MD_FLTYPE | OBD_MD_FLMODE | + OBD_MD_FLID | OBD_MD_FLUID | OBD_MD_FLGID; rc = obj_ioctl(OBD_IOC_CREATE, &data, 1); if (rc) { @@ -496,7 +500,7 @@ static int obj_create(struct kid_t *kid) return rc; } - kid->k_objid = data.ioc_obdo1.o_id; + kid->k_objid = ostid_id(&data.ioc_obdo1.o_oi); if (o_verbose > 4) printf("%d: cr "LPX64"\n", kid->k_id, kid->k_objid); @@ -515,7 +519,7 @@ static int obj_delete(struct kid_t *kid) memset(&data, 0, sizeof(data)); data.ioc_dev = kid->k_dev; - data.ioc_obdo1.o_id = kid->k_objid; + ostid_set_id(&data.ioc_obdo1.o_oi, kid->k_objid); data.ioc_obdo1.o_mode = S_IFREG | 0644; data.ioc_obdo1.o_valid = OBD_MD_FLID | OBD_MD_FLMODE; @@ -555,13 +559,14 @@ static int obj_write(struct kid_t *kid) data.ioc_pbuf1 = (void *)1; data.ioc_plen1 = 1; - data.ioc_obdo1.o_id = kid->k_objid; - data.ioc_obdo1.o_mode = S_IFREG; - data.ioc_obdo1.o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLMODE | - OBD_MD_FLFLAGS; - data.ioc_obdo1.o_flags = OBD_FL_DEBUG_CHECK; - data.ioc_count = len; - data.ioc_offset = 0; + ostid_set_seq_echo(&data.ioc_obdo1.o_oi); + ostid_set_id(&data.ioc_obdo1.o_oi, kid->k_objid); + data.ioc_obdo1.o_mode = S_IFREG; + data.ioc_obdo1.o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLMODE | + OBD_MD_FLFLAGS | OBD_MD_FLGROUP; + data.ioc_obdo1.o_flags = OBD_FL_DEBUG_CHECK; + data.ioc_count = len; + data.ioc_offset = 0; gettimeofday(&start, NULL); @@ -665,21 +670,31 @@ static void report_perf() static void *run_one_child(void *threadvp) { - struct kid_t *kid; - char oname[10], ename[10]; - int thread = (long)threadvp, dev = 0; - int rc = 0, err; - - if (o_verbose > 2) - printf("%s: running thread #%d\n", cmdname, thread); - - sprintf(oname, "o%.5d", thread); - sprintf(ename, "e%.5d", thread); + struct kid_t *kid; + char oname[16], ename[16]; + int thread = (long)threadvp; + int dev = 0; + int err; + int rc; + + if (o_verbose > 2) + printf("%s: running thread #%d\n", cmdname, thread); + + rc = snprintf(oname, sizeof(oname), "o%.5d", thread); + if (rc != 1) { + rc = -EFAULT; + goto out_exit; + } + rc = snprintf(ename, sizeof(ename), "e%.5d", thread); + if (rc != 1) { + rc = -EFAULT; + goto out_exit; + } rc = echocli_setup(oname, ename, &dev); if (rc) { fprintf(stderr, "%s: can't setup '%s/%s' (%d)\n", cmdname, oname, ename, rc); - pthread_exit((void *)(long)rc); + goto out_exit; } kid = push_kid(thread); @@ -691,12 +706,14 @@ static void *run_one_child(void *threadvp) while(!(rc || sig_received)) { pthread_mutex_lock(&m_trigger); + pthread_mutex_lock(&m_list); waiting_count++; if ((waiting_count == live_threads) && timer_on) { report_perf(); timer_on = 0; all_done = 1; } + pthread_mutex_unlock(&m_list); pthread_cond_wait(&cv_trigger, &m_trigger); waiting_count--; all_done = 0; @@ -729,9 +746,23 @@ out: err = cleanup(oname, 0); if (!rc) rc = err; - pthread_exit((void *)(long)rc); +out_exit: + pthread_exit((void *)(long)rc); } +/* + * PTHREAD_STACK_MIN is 16K minimal stack for threads. This + * is stack consumed by one thread, which executes NULL procedure. + * We need some more here and 20k stack for one client thread + * is enough to not overflow. In same time it does not consume + * a lot of memory for large number of threads. + * + * 20K virtual clients will only consume 320M + 400M. Still to + * create this number of virtual clients we need to fix 8192 + * OBDs limit. + */ +#define CLIENT_THREAD_STACK_SIZE (PTHREAD_STACK_MIN + (20 * 1024)) + static int loadgen_start_clients(int argc, char **argv) { int rc = 0, i, numt; @@ -757,7 +788,7 @@ static int loadgen_start_clients(int argc, char **argv) cmdname, rc, strerror(errno)); return -errno; } - pthread_attr_setstacksize (&attr, PTHREAD_STACK_MIN); + pthread_attr_setstacksize (&attr, CLIENT_THREAD_STACK_SIZE); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); numt += live_threads; @@ -862,13 +893,17 @@ static int loadgen_write(int argc, char **argv) if (argc < 3 || argc > 4) return CMD_HELP; threads = atoi(argv[1]); + pthread_mutex_lock(&m_list); if (threads > live_threads) { + pthread_mutex_unlock(&m_list); fprintf(stderr, "requested %d threads but only %d are running. " "Use 'start' to start some more.\n", threads, live_threads); return -EOVERFLOW; + } else { + pthread_mutex_unlock(&m_list); } - trigger(C_WRITE, threads, atoi(argv[2]), + trigger(C_WRITE, threads, atoi(argv[2]), (argc == 4) ? atoi(argv[3]) : 0); return 0; } @@ -917,7 +952,7 @@ static int loadgen_start_echosrv(int argc, char **argv) cmdname, rc); goto clean; } - + /* Create an OSS to handle the communications */ /* attach ost OSS OSS_UUID */ args[1] = "ost"; @@ -956,7 +991,7 @@ clean: static int loadgen_wait(int argc, char **argv) { - /* Give scripts a chance to start some threads */ + /* Give scripts a chance to start some threads */ sleep(1); while (!all_done) { sleep(1); @@ -996,7 +1031,7 @@ static int loadgen_init(int argc, char **argv) static int loadgen_exit() { int rc; - + printf("stopping %d children\n", live_threads); kill_kids(); rc = wait_for_threads(); @@ -1038,7 +1073,7 @@ static int loadgen_main(int argc, char **argv) out: obd_finalize(argc, argv); - return rc; + return rc < 0 ? -rc : rc; } #ifndef LIBLUSTRE_TEST