From 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 20:24:20 +0200 Subject: Adding upstream version 14.2.21. Signed-off-by: Daniel Baumann --- src/test/old/test_disk_bw.cc | 62 ++++++++++ src/test/old/test_seek_read.c | 63 +++++++++++ src/test/old/test_setlayout.c | 24 ++++ src/test/old/test_short_seek_read.c | 70 ++++++++++++ src/test/old/testbucket.cc | 67 +++++++++++ src/test/old/testbuffers.cc | 40 +++++++ src/test/old/testcounter.cc | 73 ++++++++++++ src/test/old/testcrush.cc | 219 ++++++++++++++++++++++++++++++++++++ src/test/old/testfilepath.cc | 22 ++++ src/test/old/testmpi.cc | 53 +++++++++ src/test/old/testnewbuffers.cc | 91 +++++++++++++++ src/test/old/testtree.cc | 46 ++++++++ src/test/old/testxattr.cc | 29 +++++ 13 files changed, 859 insertions(+) create mode 100644 src/test/old/test_disk_bw.cc create mode 100644 src/test/old/test_seek_read.c create mode 100644 src/test/old/test_setlayout.c create mode 100644 src/test/old/test_short_seek_read.c create mode 100644 src/test/old/testbucket.cc create mode 100644 src/test/old/testbuffers.cc create mode 100644 src/test/old/testcounter.cc create mode 100644 src/test/old/testcrush.cc create mode 100644 src/test/old/testfilepath.cc create mode 100644 src/test/old/testmpi.cc create mode 100644 src/test/old/testnewbuffers.cc create mode 100644 src/test/old/testtree.cc create mode 100644 src/test/old/testxattr.cc (limited to 'src/test/old') diff --git a/src/test/old/test_disk_bw.cc b/src/test/old/test_disk_bw.cc new file mode 100644 index 00000000..d509a510 --- /dev/null +++ b/src/test/old/test_disk_bw.cc @@ -0,0 +1,62 @@ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "common/Clock.h" +#include "common/safe_io.h" + +#include +using namespace std; + +int main(int argc, char **argv) +{ + void *buf; + int fd, count, loop = 0; + + if (argc != 4) { + fprintf(stderr, "Usage: %s device bsize count\n", argv[0]); + exit (0); + } + + int bsize = atoi(argv[2]); + count = atoi(argv[3]); + + posix_memalign(&buf, sysconf(_SC_PAGESIZE), bsize); + + //if ((fd = open(argv[1], O_SYNC|O_RDWR)) < 0) { + if ((fd = open(argv[1], O_DIRECT|O_RDWR)) < 0) { + + fprintf(stderr, "Can't open device %s\n", argv[1]); + exit (4); + } + + + utime_t start = ceph_clock_now(); + while (loop++ < count) { + int ret = safe_write(fd, buf, bsize); + if (ret) + ceph_abort(); + //if ((loop % 100) == 0) + //fprintf(stderr, "."); + } + ::fsync(fd); + ::close(fd); + utime_t end = ceph_clock_now(); + end -= start; + + + char hostname[80]; + gethostname(hostname, 80); + + double mb = bsize*count/1024/1024; + + cout << hostname << "\t" << mb << " MB\t" << end << " seconds\t" << (mb / (double)end) << " MB/sec" << std::endl; +} diff --git a/src/test/old/test_seek_read.c b/src/test/old/test_seek_read.c new file mode 100644 index 00000000..c63ed34d --- /dev/null +++ b/src/test/old/test_seek_read.c @@ -0,0 +1,63 @@ +#include "include/types.h" +#include "common/Clock.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char **argv) +{ + char *fn = argv[1]; + + int fd = ::open(fn, O_RDWR|O_DIRECT);//|O_SYNC|O_DIRECT); + if (fd < 0) return 1; + + uint64_t bytes = 0; + int r = ioctl(fd, BLKGETSIZE64, &bytes); + uint64_t numblocks = bytes / 4096; + + //uint64_t numblocks = atoll(argv[2]) * 4;// / 4096; + int count = 1000; + + cout << "fn " << fn << endl; + cout << "numblocks " << numblocks << endl; + + int blocks = 1; + while (blocks <= 1024) { + //cout << "fd is " << fd << endl; + + void *buf; + ::posix_memalign(&buf, 4096, 4096*blocks); + + int s = blocks*4096; + + utime_t start = ceph_clock_now(); + for (int i=0; i +#include +#include +#include "include/ceph_fs.h" +#include +#include +#include + +#include "kernel/ioctl.h" + + +main() { + struct ceph_file_layout l; + int fd = open("foo.txt", O_RDONLY); + int r = ioctl(fd, CEPH_IOC_GET_LAYOUT, &l, sizeof(l)); + printf("get = %d\n", r); + + l.fl_stripe_unit = 65536; + l.fl_object_size = 65536; + + r = ioctl(fd, CEPH_IOC_SET_LAYOUT, &l, sizeof(l)); + printf("set = %d\n", r); +} diff --git a/src/test/old/test_short_seek_read.c b/src/test/old/test_short_seek_read.c new file mode 100644 index 00000000..9737025a --- /dev/null +++ b/src/test/old/test_short_seek_read.c @@ -0,0 +1,70 @@ +#include "include/types.h" +#include "common/Clock.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char **argv) +{ + char *fn = argv[1]; + + int fd = ::open(fn, O_RDWR|O_DIRECT);//|O_SYNC|O_DIRECT); + if (fd < 0) return 1; + + uint64_t bytes = 0; + int r = ioctl(fd, BLKGETSIZE64, &bytes); + uint64_t numblocks = bytes / 4096; + + //uint64_t numblocks = atoll(argv[2]) * 4;// / 4096; + int count = 1000; + + cout << "fn " << fn << endl; + cout << "numblocks " << numblocks << endl; + + int blocks = 1; + while (blocks <= 1024) { + //cout << "fd is " << fd << endl; + + void *buf; + ::posix_memalign(&buf, 4096, 4096*blocks); + + int s = blocks*4096; + + double timeper = 0.0; + for (int i=0; i +#include +using namespace std; + + +ostream& operator<<(ostream &out, const vector &v) +{ + out << "["; + for (int i=0; i disks; + for (int i=0; i<20; i++) + disks.push_back(i); + + + /* + UniformBucket ub(1, 1, 0, 10, disks); + ub.make_primes(h); + cout << "primes are " << ub.primes << endl; + */ + + MixedBucket mb(2, 1); + for (int i=0;i<20;i++) + mb.add_item(i, 10); + + /* + MixedBucket b(3, 1); + b.add_item(1, ub.get_weight()); + b.add_item(2, mb.get_weight()); + */ + MixedBucket b= mb; + + vector ocount(disks.size()); + int numrep = 3; + + vector v(numrep); + for (int x=1; x<1000000; x++) { + //cout << H(x) << "\t" << h(x) << endl; + for (int i=0; i +using namespace std; + +#include "include/bufferlist.h" + + +int main() +{ + + bufferptr p1 = new buffer("123456",6); + bufferptr p2 = p1; + + cout << "it is '" << p1.c_str() << "'" << endl; + + bufferptr p3 = new buffer("abcdef",6); + + cout << "p3 is " << p3 << endl; + + bufferlist bl; + bl.push_back(p2); + bl.push_back(p1); + bl.push_back(p3); + + cout << "bl is " << bl << endl; + + cout << "len is " << bl.length() << endl; + + bufferlist took; + bl.splice(10,4,&took); + + cout << "took out " << took << "leftover is " << bl << endl; + //cout << "len is " << bl.length() << endl; + + bufferlist bl2; + bl2.substr_of(bl, 3, 5); + cout << "bl2 is " << bl2 << endl; + + +} diff --git a/src/test/old/testcounter.cc b/src/test/old/testcounter.cc new file mode 100644 index 00000000..4e40914f --- /dev/null +++ b/src/test/old/testcounter.cc @@ -0,0 +1,73 @@ + +#include "common/DecayCounter.h" + +#include + +#include +using namespace std; + +struct RealCounter { +public: + list hits; + + void hit(int ms) { + hits.push_back(ms); + } + + int get(double hl, int now) { + trim(now-hl); + return hits.size(); + } + + void trim(int to) { + while (!hits.empty() && + hits.front() < to) + hits.pop_front(); + } + + +}; + +int main(int argc, char **argv) +{ + int target; + double hl = atof(argv[1]); + cerr << "halflife " << hl << endl; + + DecayCounter dc(hl); + RealCounter rc; + + DecayCounter::time now = DecayCounter::clock::now(); + + for (int ms=0; ms < 300*1000; ms++) { + if (ms % 30000 == 0) { + target = 1 + (rand() % 10) * 10; + if (ms > 200000) target = 0; + } + + if (target && + (rand() % (1000/target) == 0)) { + dc.hit(); + rc.hit(ms); + } + + if (ms % 500 == 0) dc.get(now); + if (ms % 100 == 0) { + //dc.get(now); + DecayCounter o = dc; + cout << ms << "\t" + << target*hl << "\t" + << rc.get(hl*1000, ms) << "\t" + << o.get(now) << "\t" + << dc.val << "\t" + // << dc.delta << "\t" + << o.get_last_vel() << "\t" + << o.get_last() + o.get_last_vel() << "\t" + << endl; + } + + usleep(1); + now = DecayCounter::clock::now(); + } + +} diff --git a/src/test/old/testcrush.cc b/src/test/old/testcrush.cc new file mode 100644 index 00000000..56bb7240 --- /dev/null +++ b/src/test/old/testcrush.cc @@ -0,0 +1,219 @@ +#include "../crush/crush.h" +using namespace crush; + +#include + +#include +#include +using namespace std; + +void make_disks(int n, int& no, vector& d) +{ + d.clear(); + while (n) { + d.push_back(no); + no++; + n--; + } +} + +Bucket *make_bucket(Crush& c, vector& wid, int h, int& ndisks, int& nbuckets) +{ + if (h == 0) { + // uniform + Hash hash(123); + vector disks; + for (int i=0; imake_primes(hash); + c.add_bucket(b); + return b; + } else { + // mixed + MixedBucket *b = new MixedBucket(nbuckets--, h+1); + for (int i=0; iadd_item(n->get_id(), n->get_weight()); + } + c.add_bucket(b); + return b; + } +} + +int make_hierarchy(Crush& c, vector& wid, int& ndisks, int& nbuckets) +{ + Bucket *b = make_bucket(c, wid, wid.size()-1, ndisks, nbuckets); + return b->get_id(); +} + + + +int main() +{ + Hash h(73232313); + + // crush + Crush c; + + // buckets + vector disks; + int root = -1; + int nbuckets = -1; + int ndisks = 0; + + if (0) { + make_disks(12, ndisks, disks); + UniformBucket ub1(-1, 1, 0, 30, disks); + ub1.make_primes(h); + cout << "ub1 primes are " << ub1.primes << endl; + c.add_bucket(&ub1); + + make_disks(17, ndisks, disks); + UniformBucket ub2(-2, 1, 0, 30, disks); + ub2.make_primes(h); + cout << "ub2 primes are " << ub2.primes << endl; + c.add_bucket(&ub2); + + make_disks(4, ndisks, disks); + UniformBucket ub3(-3, 1, 0, 30, disks); + ub3.make_primes(h); + cout << "ub3 primes are " << ub3.primes << endl; + c.add_bucket(&ub3); + + make_disks(20, ndisks, disks); + MixedBucket umb1(-4, 1); + for (int i=0; i<20; i++) + umb1.add_item(disks[i], 30); + c.add_bucket(&umb1); + + MixedBucket b(-100, 1); + b.add_item(-4, umb1.get_weight()); + } + + if (0) { + int bucket = -1; + MixedBucket *root = new MixedBucket(bucket--, 2); + + for (int i=0; i<5; i++) { + MixedBucket *b = new MixedBucket(bucket--, 1); + + int n = 5; + + if (1) { + // add n buckets of n disks + for (int j=0; jadd_item(disks[k], 10); + + c.add_bucket(d); + b->add_item(d->get_id(), d->get_weight()); + } + + c.add_bucket(b); + root->add_item(b->get_id(), b->get_weight()); + } else { + // add n*n disks + make_disks(n*n, ndisks, disks); + for (int k=0; kadd_item(disks[k], 10); + + c.add_bucket(b); + root->add_item(b->get_id(), b->get_weight()); + } + } + + c.add_bucket(root); + } + + + if (1) { + vector wid; + for (int d=0; d<5; d++) + wid.push_back(10); + root = make_hierarchy(c, wid, ndisks, nbuckets); + } + + // rule + int numrep = 1; + + Rule rule; + if (0) { + rule.steps.push_back(RuleStep(CRUSH_RULE_TAKE, -100)); + rule.steps.push_back(RuleStep(CRUSH_RULE_CHOOSE, numrep, 0)); + } + if (1) { + rule.steps.push_back(RuleStep(CRUSH_RULE_TAKE, root)); + rule.steps.push_back(RuleStep(CRUSH_RULE_CHOOSE, 1, 0)); + rule.steps.push_back(RuleStep(CRUSH_RULE_EMIT)); + } + + int pg_per = 100; + int numpg = pg_per*ndisks/numrep; + + vector ocount(ndisks); + cout << ndisks << " disks, " << 1-nbuckets << " buckets" << endl; + cout << pg_per << " pgs per disk" << endl; + cout << numpg << " logical pgs" << endl; + cout << "numrep is " << numrep << endl; + + + int place = 1000000; + int times = place / numpg; + if (!times) times = 1; + + cout << "looping " << times << " times" << endl; + + float tvar = 0; + int tvarnum = 0; + + int x = 0; + for (int t=0; t v(numrep); + + for (int z=0; z +using namespace std; + +int print(const string &s) { + filepath fp = s; + cout << "s = " << s << " filepath = " << fp << endl; + cout << " depth " << fp.depth() << endl; + for (int i=0; i +#include +#include +using namespace std; + +#include "common/config.h" +#include "messages/MPing.h" +#include "common/Mutex.h" + +#include "msg/MPIMessenger.h" + +class Pinger : public Dispatcher { +public: + Messenger *messenger; + explicit Pinger(Messenger *m) : messenger(m) { + m->set_dispatcher(this); + } + void dispatch(Message *m) { + //dout(1) << "got incoming " << m << endl; + delete m; + + } +}; + +int main(int argc, char **argv) { + int num = 1000; + + int myrank = mpimessenger_init(argc, argv); + int world = mpimessenger_world(); + + Pinger *p = new Pinger( new MPIMessenger(myrank) ); + + mpimessenger_start(); + + //while (1) { + for (int i=0; i<10000; i++) { + + // ping random nodes + int d = rand() % world; + if (d != myrank) { + //cout << "sending " << i << " to " << d << endl; + p->messenger->send_message(new MPing(), d); + } + + } + + + //cout << "shutting down" << endl; + //p->messenger->shutdown(); + + mpimessenger_wait(); + mpimessenger_shutdown(); // shutdown MPI +} diff --git a/src/test/old/testnewbuffers.cc b/src/test/old/testnewbuffers.cc new file mode 100644 index 00000000..69e037c7 --- /dev/null +++ b/src/test/old/testnewbuffers.cc @@ -0,0 +1,91 @@ + +#include +#include +using namespace std; + + +#include "include/newbuffer.h" +//#include "include/bufferlist.h" + +#include "common/Thread.h" + + + class Th : public Thread { + public: + bufferlist bl; + explicit Th(bufferlist& o) : bl(o) { } + + void *entry() { + //cout << "start" << endl; + // thrash it a bit. + for (int n=0; n<10000; n++) { + bufferlist bl2; + unsigned off = rand() % (bl.length() -1); + unsigned len = 1 + rand() % (bl.length() - off - 1); + bl2.substr_of(bl, off, len); + bufferlist bl3; + bl3.append(bl); + bl3.append(bl2); + //cout << bl3 << endl; + bl2.clear(); + bl3.clear(); + } + //cout << "end" << endl; + } + }; + +int main() +{ + + bufferptr p1 = buffer::copy("123456",7); + //bufferptr p1 = new buffer("123456",7); + bufferptr p2 = p1; + + cout << "p1 is '" << p1.c_str() << "'" << " " << p1 << endl; + cout << "p2 is '" << p2.c_str() << "'" << " " << p2 << endl; + + bufferptr p3 = buffer::copy("abcdef",7); + //bufferptr p3 = new buffer("abcdef",7); + + cout << "p3 is " << p3.c_str() << " " << p3 << endl; + + bufferlist bl; + bl.push_back(p2); + bl.push_back(p1); + bl.push_back(p3); + + cout << "bl is " << bl << endl; + + bufferlist took; + bl.splice(10,4,&took); + + cout << "took out " << took << ", leftover is " << bl << endl; + //cout << "len is " << bl.length() << endl; + + bufferlist bl2; + bl2.substr_of(bl, 3, 5); + cout << "bl2 is " << bl2 << endl; + + + cout << "bl before " << bl << endl; + + list ls; + for (int t=0; t<40; t++) { + Th *t = new Th(bl); + cout << "create" << endl; + t->create(); + ls.push_back(t); + } + + bl.clear(); + + while (!ls.empty()) { + cout << "join" << endl; + ls.front()->join(); + delete ls.front(); + ls.pop_front(); + } + + cout << "bl after " << bl << endl; + +} diff --git a/src/test/old/testtree.cc b/src/test/old/testtree.cc new file mode 100644 index 00000000..2c21bcbe --- /dev/null +++ b/src/test/old/testtree.cc @@ -0,0 +1,46 @@ + + +#include "../crush/BinaryTree.h" +using namespace crush; + +#include +#include +using namespace std; + +int main() +{ + BinaryTree t; + + vector nodes; + + for (int i=0; i<30; i++) { + cout << "adding " << i << endl; + int n = t.add_node(1); + nodes.push_back(n); + //cout << t << endl; + } + cout << t << endl; + + for (int k=0; k<10000; k++) { + if (rand() % 2) { + cout << "adding" << endl; + nodes.push_back( t.add_node(1) ); + } else { + if (!nodes.empty()) { + //for (int i=0; i +using namespace std; + + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char**argv) +{ + int a = 1; + int b = 2; + + mknod("test", 0600, 0); + + cout << "setxattr " << setxattr("test", "asdf", &a, sizeof(a), 0) << endl; + cout << "errno " << errno << " " << strerror(errno) << endl; + cout << "getxattr " << getxattr("test", "asdf", &b, sizeof(b)) << endl; + cout << "errno " << errno << " " << strerror(errno) << endl; + cout << "a is " << a << " and b is " << b << endl; + return 0; +} -- cgit v1.2.3