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 
26 BenchMark::BenchMark(int argc, char **argv)
27  : POSIXApplication(argc, argv)
28 {
29  parser().setDescription("Perform system benchmark tests");
30 }
31 
33 {
34 }
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 }
stat
The <sys/stat.h> header shall define the stat structure.
Definition: stat.h:176
Memory::Range
Memory range.
Definition: Memory.h:55
ProcessInfo
Process information structure, used for Info.
Definition: ProcessCtl.h:63
fcntl.h
timestamp
u64 timestamp()
Reads the CPU's timestamp counter.
Definition: IntelCore.h:41
PAGESIZE
#define PAGESIZE
ARM uses 4K pages.
Definition: ARMConstant.h:97
POSIXApplication
POSIX-compatible application.
Definition: POSIXApplication.h:35
Address
unsigned long Address
A memory address.
Definition: Types.h:131
Application::Success
@ Success
Definition: Application.h:55
VMCtl
API::Result VMCtl(const ProcessID procID, const MemoryOperation op, Memory::Range *range=ZERO)
Prototype for user applications.
Definition: VMCtl.h:61
ArgumentParser::setDescription
void setDescription(const String &desc)
Set program description.
Definition: ArgumentParser.cpp:95
ProcessCtl
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
BenchMark.h
SELF
#define SELF
Definition: ProcessID.h:35
u64
unsigned long long u64
Unsigned 64-bit number.
Definition: Types.h:50
InfoPID
@ InfoPID
Definition: ProcessCtl.h:47
printf
int printf(const char *format,...)
Output a formatted string to standard output.
Definition: printf.cpp:22
GetPID
@ GetPID
Definition: ProcessCtl.h:41
stdio.h
u32
unsigned int u32
Unsigned 32-bit number.
Definition: Types.h:53
Application::Result
Result
Result codes.
Definition: Application.h:53
BenchMark::exec
virtual Result exec()
Execute the application.
Definition: BenchMark.cpp:36
stat
int stat(const char *path, struct stat *buf)
Get file status.
Definition: stat.cpp:25
BenchMark::~BenchMark
virtual ~BenchMark()
Destructor.
Definition: BenchMark.cpp:32
BenchMark::BenchMark
BenchMark(int argc, char **argv)
Constructor.
Definition: BenchMark.cpp:26
LookupVirtual
@ LookupVirtual
Definition: VMCtl.h:42
stat.h
unistd.h
Application::parser
ArgumentParser & parser()
Get program arguments parser.
Definition: Application.cpp:102
Schedule
@ Schedule
Definition: ProcessCtl.h:52
Memory::Range::virt
Address virt
Virtual address.
Definition: Memory.h:57
stdlib.h
Memory::Range::size
Size size
Size in number of bytes.
Definition: Memory.h:59