代码拉取完成,页面将自动刷新
同步操作将从 HoperunHarmony/stress-ng 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
/*
* Copyright (C) 2013-2021 Canonical, Ltd.
* Copyright (C) 2022 Colin Ian King.
*
* This program 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 2
* of the License, or (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "stress-ng.h"
#include "core-capabilities.h"
static const char bitmap_file[] = "/sys/kernel/mm/page_idle/bitmap";
static const stress_help_t help[] = {
{ NULL, "idle-page N", "start N idle page scanning workers" },
{ NULL, "idle-page-ops N", "stop after N idle page scan bogo operations" },
{ NULL, NULL, NULL }
};
/*
* stress_idle_page_supported()
* check if we can run this as root
*/
static int stress_idle_page_supported(const char *name)
{
if (!stress_check_capability(SHIM_CAP_SYS_RESOURCE)) {
pr_inf_skip("%s stressor will be skipped, "
"need to be running with CAP_SYS_RESOURCE "
"rights for this stressor\n", name);
return -1;
}
if (geteuid() != 0) {
pr_inf_skip("%s stressor will be skipped, "
"need to be running as root for this stressor\n", name);
return -1;
}
if (access(bitmap_file, R_OK) != 0) {
pr_inf_skip("%s stressor will be skipped, "
"cannot access file %s\n", bitmap_file, name);
return -1;
}
return 0;
}
#if defined(__linux__)
#define BITMAP_BYTES (8)
#define PAGES_TO_SCAN (64)
/*
* stress_idle_page
* stress kernel logging interface
*/
static int stress_idle_page(const stress_args_t *args)
{
int fd;
off_t posn = 0, last_posn = ~(off_t)7;
uint64_t bitmap_set[PAGES_TO_SCAN] ALIGNED(8);
fd = open(bitmap_file, O_RDWR);
if (fd < 0) {
if (args->instance == 0)
pr_inf("idle_page stressor will be skipped, "
"cannot access file %s\n", bitmap_file);
return EXIT_NO_RESOURCE;
}
(void)memset(bitmap_set, 0xff, sizeof(bitmap_set));
stress_set_proc_state(args->name, STRESS_STATE_RUN);
do {
off_t oret;
ssize_t ret;
uint64_t bitmap_get[PAGES_TO_SCAN] ALIGNED(8);
oret = lseek(fd, posn, SEEK_SET);
if (oret == (off_t)-1)
goto next;
ret = write(fd, bitmap_set, sizeof(bitmap_set));
if ((ret < 0) && (errno == ENXIO)) {
posn = 0;
goto next;
}
oret = lseek(fd, posn, SEEK_SET);
if (oret == (off_t)-1)
goto next;
ret = read(fd, &bitmap_get, BITMAP_BYTES);
if ((ret < 0) && (errno == ENXIO)) {
posn = 0;
goto next;
}
last_posn = posn;
posn += sizeof(bitmap_set);
inc_counter(args);
next:
if (posn == last_posn) {
pr_inf("%s: aborting early, seek position not advancing\n",
args->name);
break;
}
} while (keep_stressing(args));
stress_set_proc_state(args->name, STRESS_STATE_DEINIT);
(void)close(fd);
return EXIT_SUCCESS;
}
stressor_info_t stress_idle_page_info = {
.stressor = stress_idle_page,
.supported = stress_idle_page_supported,
.class = CLASS_OS,
.help = help
};
#else
stressor_info_t stress_idle_page_info = {
.stressor = stress_not_implemented,
.supported = stress_idle_page_supported,
.class = CLASS_OS,
.help = help
};
#endif
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。