FreeNOS
BenchMark.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2009 Niek Linnenbank
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include <FreeNOS/System.h>
19#include <stdio.h>
20#include <stdlib.h>
21#include <fcntl.h>
22#include <unistd.h>
23#include <sys/stat.h>
24#include "BenchMark.h"
25
26BenchMark::BenchMark(int argc, char **argv)
27 : POSIXApplication(argc, argv)
28{
29 parser().setDescription("Perform system benchmark tests");
30}
31
35
37{
38 u64 t1 = 0, t2 = 0;
39 ProcessInfo info;
40 Memory::Range range;
41 char *foo[128];
42 struct stat st;
43
44 // Retrieve current process ID with kernel trap
45 t1 = timestamp();
47 t2 = timestamp();
48 printf("SystemCall (GetPID) Ticks: %u\r\n", t2 - t1);
49
50 // Retrieve current process information
51 t1 = timestamp();
52 ProcessCtl(SELF, InfoPID, (Address) &info);
53 t2 = timestamp();
54 printf("SystemCall (InfoPID) Ticks: %u\r\n", t2 - t1);
55
56 // Perform task schedule
57 t1 = timestamp();
59 t2 = timestamp();
60 printf("SystemCall (Schedule) Ticks: %u\r\n", t2 - t1);
61
62 // Translate virtual memory address to physical memory address
63 range.virt = 0x80000000;
64 range.size = PAGESIZE;
65 t1 = timestamp();
66 VMCtl(SELF, LookupVirtual, &range);
67 t2 = timestamp();
68 printf("SystemCall (VMCtl) Ticks: %u\r\n", t2 - t1);
69
70 // Perform inter-process communication call
71 t1 = timestamp();
72 stat("/etc", &st);
73 t2 = timestamp();
74 printf("IPC (stat) Ticks: %u\r\n", t2 - t1);
75
76 // Allocate heap memory
77 t1 = timestamp();
78 for (int i = 0; i < 128; i++)
79 foo[i] = new char[16];
80 t2 = timestamp();
81 printf("allocate() Ticks: %u (%u AVG)\r\n",
82 (u32)(t2 - t1), (u32)(t2 - t1) / 128);
83
84 // Release heap memory
85 t1 = timestamp();
86 for (int i = 0; i < 128; i++)
87 delete foo[i];
88 t2 = timestamp();
89 printf("release() Ticks: %u (%u AVG)\r\n",
90 (u32)(t2 - t1), (u32)(t2 - t1) / 128);
91
92 // Done
93 return Success;
94}
Result
Result codes.
Definition Application.h:54
ArgumentParser & parser()
Get program arguments parser.
void setDescription(const String &desc)
Set program description.
virtual Result exec()
Execute the application.
Definition BenchMark.cpp:36
BenchMark(int argc, char **argv)
Constructor.
Definition BenchMark.cpp:26
virtual ~BenchMark()
Destructor.
Definition BenchMark.cpp:32
POSIX-compatible application.
#define SELF
Definition ProcessID.h:35
API::Result ProcessCtl(const ProcessID proc, const ProcessOperation op, const Address addr=0, const Address output=0)
Prototype for user applications.
Definition ProcessCtl.h:93
API::Result VMCtl(const ProcessID procID, const MemoryOperation op, Memory::Range *range=ZERO)
Prototype for user applications.
Definition VMCtl.h:61
@ LookupVirtual
Definition VMCtl.h:42
@ InfoPID
Definition ProcessCtl.h:47
@ GetPID
Definition ProcessCtl.h:41
@ Schedule
Definition ProcessCtl.h:52
#define PAGESIZE
ARM uses 4K pages.
Definition ARMConstant.h:97
#define timestamp()
Reads the CPU's timestamp counter.
Definition ARMCore.h:97
C int printf(const char *format,...)
Output a formatted string to standard output.
Definition printf.cpp:22
unsigned int u32
Unsigned 32-bit number.
Definition Types.h:53
unsigned long Address
A memory address.
Definition Types.h:131
unsigned long long u64
Unsigned 64-bit number.
Definition Types.h:50
Memory range.
Definition Memory.h:56
Size size
Size in number of bytes.
Definition Memory.h:59
Address virt
Virtual address.
Definition Memory.h:57
Process information structure, used for Info.
Definition ProcessCtl.h:64
The <sys/stat.h> header shall define the stat structure.
Definition stat.h:177