]>
git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gprofng/testsuite/gprofng.display/synprog/pagethrash.c
1 /* Copyright (C) 2021-2023 Free Software Foundation, Inc.
4 This file is part of GNU Binutils.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
24 #include "stopwatch.h"
26 /*=======================================================*/
28 /* pagethrash - allocate some memory, and thrash around in it */
30 pagethrash (int thrashmb
)
34 hrtime_t start
= gethrtime ();
35 hrtime_t vstart
= gethrvtime ();
38 wlog ("start of pagethrash", NULL
);
40 /* Start a stopwatch */
41 stopwatch_t
*w
= stpwtch_alloc ("pagethrash", 0);
43 /* compute the size */
44 unsigned long size
= thrashmb
* 1024 * 1024;
45 int pagesize
= getpagesize ();
46 void *space
= malloc (size
+ pagesize
);
49 fprintf (stderr
, "\tpagethrash failed; can't get %ld bytes.\n", size
);
53 /* round address to page boundary */
54 unsigned long loc
= (((unsigned long) space
+ pagesize
- 1) & ~(pagesize
- 1));
55 long npages
= size
/ pagesize
;
57 /* touch all the pages to force them in */
58 for (long i
= 0; i
< npages
; i
++)
61 *(int *) (loc
+ i
* pagesize
) = i
;
65 /* now free up the space */
68 /* print the timing results */
72 sprintf (buf
, "pagethrash: %ld pages", npages
);
73 whrvlog (gethrtime () - start
, gethrvtime () - vstart
, buf
, NULL
);