168 lines
4.6 KiB
C
168 lines
4.6 KiB
C
/*
|
|
* VAS_EBOOT -- GRand Unified Bootloader
|
|
* Copyright (C) 2022 Free Software Foundation, Inc.
|
|
* Copyright (C) 2022 IBM Corporation
|
|
*
|
|
* VAS_EBOOT is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* VAS_EBOOT is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with VAS_EBOOT. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include <config.h>
|
|
#include <VasEBoot/dl.h>
|
|
#include <VasEBoot/misc.h>
|
|
#include <VasEBoot/command.h>
|
|
#include <VasEBoot/i18n.h>
|
|
#include <VasEBoot/memory.h>
|
|
#include <VasEBoot/mm.h>
|
|
|
|
VAS_EBOOT_MOD_LICENSE ("GPLv3+");
|
|
|
|
static VasEBoot_err_t
|
|
VasEBoot_cmd_lsmem (VasEBoot_command_t cmd __attribute__ ((unused)),
|
|
int argc __attribute__ ((unused)),
|
|
char **args __attribute__ ((unused)))
|
|
|
|
{
|
|
#ifndef VAS_EBOOT_MACHINE_EMU
|
|
VasEBoot_mm_dump (0);
|
|
#endif
|
|
|
|
return 0;
|
|
}
|
|
|
|
static VasEBoot_err_t
|
|
VasEBoot_cmd_lsfreemem (VasEBoot_command_t cmd __attribute__ ((unused)),
|
|
int argc __attribute__ ((unused)),
|
|
char **args __attribute__ ((unused)))
|
|
|
|
{
|
|
#ifndef VAS_EBOOT_MACHINE_EMU
|
|
VasEBoot_mm_dump_free ();
|
|
#endif
|
|
|
|
return 0;
|
|
}
|
|
|
|
static VasEBoot_err_t
|
|
VasEBoot_cmd_lsmemregions (VasEBoot_command_t cmd __attribute__ ((unused)),
|
|
int argc __attribute__ ((unused)),
|
|
char **args __attribute__ ((unused)))
|
|
|
|
{
|
|
#ifndef VAS_EBOOT_MACHINE_EMU
|
|
VasEBoot_mm_dump_regions ();
|
|
#endif
|
|
|
|
return 0;
|
|
}
|
|
|
|
static VasEBoot_err_t
|
|
VasEBoot_cmd_stress_big_allocs (VasEBoot_command_t cmd __attribute__ ((unused)),
|
|
int argc __attribute__ ((unused)),
|
|
char **args __attribute__ ((unused)))
|
|
{
|
|
int i, max_mb, blocks_alloced;
|
|
void *mem;
|
|
void **blocklist;
|
|
|
|
VasEBoot_printf ("Test 1: increasingly sized allocs to 1GB block\n");
|
|
for (i = 1; i < 1024; i++)
|
|
{
|
|
VasEBoot_printf ("%4d MB . ", i);
|
|
mem = VasEBoot_malloc (i * 1024 * 1024);
|
|
if (mem == NULL)
|
|
{
|
|
VasEBoot_printf ("failed\n");
|
|
break;
|
|
}
|
|
else
|
|
VasEBoot_free (mem);
|
|
|
|
if (i % 7 == 0)
|
|
VasEBoot_printf ("\n");
|
|
}
|
|
|
|
max_mb = i - 1;
|
|
VasEBoot_printf ("\nMax sized allocation we did was %d MB\n", max_mb);
|
|
|
|
VasEBoot_printf ("\nTest 2: 1MB at a time, max 4GB\n");
|
|
blocklist = VasEBoot_calloc (4096, sizeof (void *));
|
|
for (i = 0; i < 4096; i++)
|
|
{
|
|
blocklist[i] = VasEBoot_malloc (1024 * 1024);
|
|
if (blocklist[i] == NULL)
|
|
{
|
|
VasEBoot_printf ("Ran out of memory at iteration %d\n", i);
|
|
break;
|
|
}
|
|
}
|
|
blocks_alloced = i;
|
|
for (i = 0; i < blocks_alloced; i++)
|
|
VasEBoot_free (blocklist[i]);
|
|
|
|
VasEBoot_printf ("\nTest 3: 1MB aligned 900kB + 100kB\n");
|
|
/* VasEBoot_mm_debug=1;*/
|
|
for (i = 0; i < 4096; i += 2)
|
|
{
|
|
blocklist[i] = VasEBoot_memalign (1024 * 1024, 900 * 1024);
|
|
if (blocklist[i] == NULL)
|
|
{
|
|
VasEBoot_printf ("Failed big allocation, iteration %d\n", i);
|
|
blocks_alloced = i;
|
|
break;
|
|
}
|
|
|
|
blocklist[i + 1] = VasEBoot_malloc (100 * 1024);
|
|
if (blocklist[i + 1] == NULL)
|
|
{
|
|
VasEBoot_printf ("Failed small allocation, iteration %d\n", i);
|
|
blocks_alloced = i + 1;
|
|
break;
|
|
}
|
|
VasEBoot_printf (".");
|
|
}
|
|
for (i = 0; i < blocks_alloced; i++)
|
|
VasEBoot_free (blocklist[i]);
|
|
|
|
VasEBoot_free (blocklist);
|
|
|
|
#if defined(__powerpc__)
|
|
VasEBoot_printf ("\nA reboot may now be required.\n");
|
|
#endif
|
|
|
|
VasEBoot_errno = VAS_EBOOT_ERR_NONE;
|
|
return VAS_EBOOT_ERR_NONE;
|
|
}
|
|
|
|
static VasEBoot_command_t cmd_lsmem, cmd_lsfreemem, cmd_lsmemregions, cmd_sba;
|
|
|
|
VAS_EBOOT_MOD_INIT (memtools)
|
|
{
|
|
cmd_lsmem = VasEBoot_register_command ("lsmem", VasEBoot_cmd_lsmem,
|
|
0, N_("List free and allocated memory blocks."));
|
|
cmd_lsfreemem = VasEBoot_register_command ("lsfreemem", VasEBoot_cmd_lsfreemem,
|
|
0, N_("List free memory blocks."));
|
|
cmd_lsmemregions = VasEBoot_register_command ("lsmemregions", VasEBoot_cmd_lsmemregions,
|
|
0, N_("List memory regions."));
|
|
cmd_sba = VasEBoot_register_command ("stress_big_allocs", VasEBoot_cmd_stress_big_allocs,
|
|
0, N_("Stress test large allocations."));
|
|
}
|
|
|
|
VAS_EBOOT_MOD_FINI (memtools)
|
|
{
|
|
VasEBoot_unregister_command (cmd_lsmem);
|
|
VasEBoot_unregister_command (cmd_lsfreemem);
|
|
VasEBoot_unregister_command (cmd_lsmemregions);
|
|
VasEBoot_unregister_command (cmd_sba);
|
|
}
|