Skip to content

Commit

Permalink
fs_mark fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdebek committed Nov 6, 2023
1 parent 9feddd4 commit 22ae431
Show file tree
Hide file tree
Showing 4 changed files with 393 additions and 10 deletions.
7 changes: 4 additions & 3 deletions fs_mark/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ done

# Build fs_mark
cd "${PREFIX_FS_MARK_BUILD}/${FS_MARK}" && make
cd "${PREFIX_FS_MARK_BUILD}/${FS_MARK}" && make install

cp -a "$PREFIX_FS_MARK_BUILD/${FS_MARK}/fs_mark" "$PREFIX_PROG/fs_mark"
"${CROSS}strip" -s "${PREFIX_PROG}/fs_mark" -o "${PREFIX_PROG_STRIPPED}/fs_mark"
b_install "$PREFIX_PORTS_INSTALL/fs_mark" /bin
#cp -a "$PREFIX_FS_MARK_BUILD/${FS_MARK}/fs_mark" "$PREFIX_PROG/fs_mark"
#"${CROSS}strip" -s "${PREFIX_PROG}/fs_mark" -o "${PREFIX_PROG_STRIPPED}/fs_mark"
#b_install "$PREFIX_PORTS_INSTALL/fs_mark" /bin
307 changes: 302 additions & 5 deletions fs_mark/patch/fs_mark.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
--- fs_mark-3.3/fs_mark.c 2023-07-10 15:47:05.889696230 +0200
+++ fs_mark-3.3.phoenix/fs_mark.c 2023-07-31 12:40:45.016383503 +0200
+++ fs_mark-3.3.phoenix/fs_mark.c 2023-11-06 20:46:51.862155955 +0100
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2004 EMC Corporation
*
* fs_mark: Benchmark synchronous/async file creation
@@ -29,7 +29,7 @@
#include <sys/types.h>
#include <sys/wait.h>
Expand All @@ -9,7 +15,7 @@
#include <sys/time.h>

#include <fcntl.h>
@@ -42,9 +42,8 @@
@@ -42,17 +42,76 @@
#include <ctype.h>
#include <time.h>

Expand All @@ -21,7 +27,92 @@

#include "fs_mark.h"

@@ -142,7 +141,8 @@
+#include <sys/mman.h>
+
+/* Define DUMMYFS_TARGET if target uses dummyfs */
+#undef DUMMYFS_TARGET
+#if defined(__CPU_IMXRT106X) || defined(__CPU_IMXRT117X) || defined(__CPU_STM32L4X6)
+#define DUMMYFS_TARGET
+#endif
+
+#ifdef DUMMYFS_TARGET
+unsigned int get_dummyfs_free_space(void)
+{
+ meminfo_t info;
+ unsigned int free_space;
+
+ info.page.mapsz = -1;
+ info.entry.kmapsz = -1;
+ info.entry.mapsz = -1;
+ info.maps.mapsz = 0;
+ info.maps.map = NULL;
+
+ meminfo(&info);
+ if (info.maps.mapsz == 0) {
+ fprintf(stderr, "mem: no shared memory maps are present\n");
+ return 1;
+ }
+
+ info.maps.map = malloc(info.maps.mapsz * sizeof(mapinfo_t));
+ if (info.maps.map == NULL) {
+ fprintf(stderr, "mem: out of memory\n");
+ return 1;
+ }
+ meminfo(&info);
+ free_space = info.maps.map[2].free;
+ if (dummyfs_size == 0) {
+ dummyfs_size = free_space;
+ }
+
+ return free_space;
+}
+
+
+void get_dummyfs_cont_blk(void)
+{
+ void *ptr;
+ size_t n;
+
+ if (errno == ENOMEM || errno == ENOSPC || errno == EIO) {
+ while((ptr = malloc(n *= 2)) == NULL) {
+ free(ptr);
+ }
+ fprintf(stderr, "Lack of contiguous memory block of size %zu" bytes, n);
+ cleanup_exit();
+ }
+}
+
+#endif
+
void cleanup_exit(void)
{
char child_log_file_name[PATH_MAX];
-
+#if NOMMU
+ sprintf(child_log_file_name, "%s.%d", log_file_name, (pid_t)-1);
+#else
sprintf(child_log_file_name, "%s.%d", log_file_name, getpid());
+#endif
unlink(child_log_file_name);

exit(1);
@@ -89,7 +148,6 @@
void process_args(int argc, char **argv, char **envp)
{
int ret;
-
/*
* Parse all of the options that the user specified.
*/
@@ -129,6 +187,7 @@
}
strncpy(child_tasks[num_dirs].test_dir, optarg,
PATH_MAX);
+
num_dirs++;
break;

@@ -142,7 +201,8 @@
break;

case 'l': /* Log file name */
Expand All @@ -31,7 +122,53 @@
break;

case 'L': /* number of iterations */
@@ -493,11 +493,11 @@
@@ -333,6 +393,9 @@
if (names == NULL) {
if ((names =
calloc(sizeof(struct name_entry), num_files)) == NULL) {
+#ifdef DUMMYFS_TARGET
+ get_dummyfs_cont_blk();
+#endif
fprintf(stderr,
"fs_mark: failed to allocate memory for file names: %s\n",
strerror(errno));
@@ -386,6 +449,9 @@
*/
if ((mkdir(names[file_index].target_dir, 0777) != 0)
&& (errno != EEXIST)) {
+#ifdef DUMMYFS_TARGET
+ get_dummyfs_cont_blk();
+#endif
fprintf(stderr, "fs_mark: mkdir %s failed: %s\n",
names[file_index].target_dir, strerror(errno));
cleanup_exit();
@@ -461,7 +527,11 @@
* Open the log file in append mode to preserve previous runs data
*/
sprintf(thread_log_file_name, "%s.%d", log_file_name, pid);
+//if (child_log_file_fp == NULL) {
if ((child_log_file_fp = fopen(thread_log_file_name, "w")) == NULL) {
+#ifdef DUMMYFS_TARGET
+ get_dummyfs_cont_blk();
+#endif
fprintf(stderr,
"fs_mark: setup failed to fopen log file: %s %s\n",
thread_log_file_name, strerror(errno));
@@ -476,9 +546,13 @@
/*
* Create my high level test directory
*/
+
my_dir = find_dir_name(pid);

if ((mkdir(my_dir, 0777) != 0) && (errno != EEXIST)) {
+#ifdef DUMMYFS_TARGET
+ get_dummyfs_cont_blk();
+#endif
fprintf(stderr,
"fill_dir:mkdir %s failed: %s\n", my_dir,
strerror(errno));
@@ -493,11 +567,11 @@
*/
int get_df_full(char *dir_name)
{
Expand All @@ -45,7 +182,20 @@
fprintf(stderr, "fs_mark: statfs failed on %s %s\n", dir_name,
strerror(errno));
cleanup_exit();
@@ -517,10 +517,10 @@
@@ -505,8 +579,11 @@

used_blocks = (float)(fs_buf.f_blocks - fs_buf.f_bavail);

+#ifdef DUMMYFS_TARGET
+ df_used = (used_blocks / dummyfs_size);
+#else
df_used = (used_blocks / fs_buf.f_blocks);
-
+#endif
df_percent_used = (int)(100 * df_used);

return (df_percent_used);
@@ -517,10 +594,10 @@
*/
unsigned long long get_bytes_free(char *dir_name)
{
Expand All @@ -58,3 +208,150 @@
fprintf(stderr, "fs_mark: statfs failed on %s %s\n", dir_name,
strerror(errno));
cleanup_exit();
@@ -560,6 +637,9 @@

start(0);
if ((ret = write(fd, io_buffer, write_size)) != write_size) {
+#ifdef DUMMYFS_TARGET
+ get_dummyfs_cont_blk();
+#endif
fprintf(stderr,
"fs_mark: write_file write failed: %d %s\n",
ret, strerror(errno));
@@ -590,7 +670,9 @@
*/
static void check_space(pid_t my_pid)
{
+#ifdef DUMMYFS_TARGET
char *my_dir_name;
+#endif
unsigned long long bytes_per_loop;

my_dir_name = find_dir_name(my_pid);
@@ -600,10 +682,16 @@
* Compute free bytes and compare to many bytes needed for this iteration.
*/
bytes_per_loop = (unsigned long long)file_size *num_files;
- if (get_bytes_free(my_dir_name) < bytes_per_loop) {
+#ifdef DUMMYFS_TARGET
+ if (get_dummyfs_free_space() < (bytes_per_loop + (4096 * 25))) {
+#else
+ // printf("free_bytes: %llu\n", get_bytes_free(my_dir_name));
+ // printf("bytes per loop: %llu\n", bytes_per_loop);
+ if (get_bytes_free(my_dir_name) < ((bytes_per_loop * num_threads) + 500000)) {
+#endif
fprintf(stdout,
- "Insufficient free space in %s to create %d new files, exiting\n",
- my_dir_name, num_files);
+ "Insufficient free space to create %d new files, exiting\n",
+ num_files * num_threads);
do_fill_fs = 0; /* Setting this signals the main loop to exit */
cleanup_exit();
}
@@ -643,6 +731,7 @@
* Once all files of a given size have been processed, the sum of the times are
* recorded in operations/sec.
*/
+ file_count = 0;
files_per_sec = 0.0;
creat_usec = max_creat_usec = min_creat_usec = 0ULL;
avg_write_usec = max_write_usec = min_write_usec = total_write_usec = 0ULL;
@@ -683,6 +772,10 @@
if ((fd =
open(file_write_name, O_CREAT | O_RDWR | O_TRUNC,
0666)) == -1) {
+#ifdef DUMMYFS_TARGET
+ get_dummyfs_cont_blk();
+#endif
+
fprintf(stderr, "Error in creat: %s\n",
strerror(errno));
cleanup_exit();
@@ -948,8 +1041,15 @@
*/
sprintf(child_log_file_name, "%s.%d", log_file_name, child_pid);
if ((thread_log_fp = fopen(child_log_file_name, "r")) == NULL) {
- fprintf(stderr, "fopen failed to open: %s\n",
- child_log_file_name);
+ if (errno != ENOENT) {
+ fprintf(stderr, "fopen failed to open: %s\n",
+ child_log_file_name);
+ fprintf(stderr, strerror(errno));
+ }
+#ifdef DUMMYFS_TARGET
+ get_dummyfs_cont_blk();
+#endif
+
cleanup_exit();
}

@@ -1107,17 +1207,40 @@
*/
void thread_work(pid_t my_pid)
{
-
/*
* Do any initialization
*/
setup(my_pid);

+#ifdef DUMMYFS_TARGET
+ get_dummyfs_free_space();
+#endif
do_run(my_pid);

fclose(child_log_file_fp);
+
+#ifdef DUMMYFS_TARGET
+ memset(names, 0, sizeof(struct name_entry) * num_files);
+#endif
+}
+
+#ifdef NOMMU
+/*
+ * On platforms with NOMMU use only 1 thread, due to lack of fork()
+ */
+void fork_threads(void)
+{
+ fflush(stdout);
+ fflush(log_file_fp);
+
+ child_tasks[0].child_pid = -1;
+ thread_work(child_tasks[0].child_pid);
+
+ return;
}

+#else
+
/*
* This routine is used only when running more than one thread (done whenever writing to
* more than one directory).
@@ -1192,6 +1315,7 @@
}
return;
}
+#endif

/*
* Print some test information and basic parameters to help user understand the rather complex options.
@@ -1261,7 +1385,7 @@
* Check how full the first directory is after each run
*/
df_full = get_df_full(child_tasks[0].test_dir);
-
+ usleep(100000);
if (verbose_stats)
fprintf(log_fp,
"%6u %12u %12u %12.1f %16llu %8llu %8llu %8llu %8llu %8llu %8llu %8llu %8llu %8llu %8llu %8llu %8llu %8llu %8llu %8llu %8llu %8llu %8llu\n",
@@ -1339,6 +1463,10 @@
* Note that each child uses its copy of this fp for its own sub log file.
*/
if ((log_file_fp = fopen(log_file_name, "a")) == NULL) {
+#ifdef DUMMYFS_TARGET
+ get_dummyfs_cont_blk();
+#endif
+
fprintf(stderr,
"fs_mark: failed to fopen log file: %s %s\n",
log_file_name, strerror(errno));
Loading

0 comments on commit 22ae431

Please sign in to comment.