Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fs_mark dummyfs support #68

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

fs_mark dummyfs support #68

wants to merge 2 commits into from

Conversation

adamdebek
Copy link
Contributor

@adamdebek adamdebek commented Oct 5, 2023

Description

Motivation and Context

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

How Has This Been Tested?

  • Already covered by automatic testing.
  • New test added: (add PR link here).
  • Tested by hand on: (list targets here).

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing linter checks and tests passed.
  • My changes generate no new compilation warnings for any of the targets.

Special treatment

  • This PR needs additional PRs to work (list the PRs, preferably in merge-order).
  • I will merge this PR by myself when appropriate.

@github-actions
Copy link

github-actions bot commented Oct 5, 2023

Unit Test Results

7 958 tests  ±0   7 416 ✅ ±0   41m 5s ⏱️ - 2m 3s
  470 suites ±0     542 💤 ±0 
    1 files   ±0       0 ❌ ±0 

Results for commit 6c64d4e. ± Comparison against base commit 1994dc6.

♻️ This comment has been updated with latest results.

@adamdebek adamdebek force-pushed the adamdebek/fs_mark branch 5 times, most recently from c31e844 to 9ca9a4a Compare October 31, 2023 13:36
@adamdebek adamdebek force-pushed the adamdebek/fs_mark branch 10 times, most recently from c67a862 to c7349d8 Compare November 7, 2023 14:15
@adamdebek adamdebek force-pushed the adamdebek/fs_mark branch 2 times, most recently from 8ba5992 to 62d697a Compare November 21, 2023 17:17
@adamdebek adamdebek changed the title fs_mark fixes fs_mark dummyfs support Nov 21, 2023
@adamdebek
Copy link
Contributor Author

To see tests results go to: phoenix-rtos/phoenix-rtos-project#802

@adamdebek adamdebek marked this pull request as ready for review November 22, 2023 09:16
build.sh Show resolved Hide resolved
Copy link
Member

@Darchiv Darchiv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have left a few comments. Passing CPPFLAGS and differentiating targets by the NOMMU define seems unnecessary. There are many fine-grained POSIX defines to use and maybe feature test macros could be employed in the future.

FS_MARK_VER="3.3"
FS_MARK=fs_mark-${FS_MARK_VER}
VER="3.3"
FS_MARK="fs_mark-$VER"
FS_MARK_COMMIT="2628be58146de63a13260ff64550f84275556c0e"
PKG_URL="https://github.com/josefbacik/fs_mark/archive/${FS_MARK_COMMIT}.tar.gz"
PKG_MIRROR_URL="https://files.phoesys.com/ports/${FS_MARK}.tar.gz"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few utility functions (and variables from build.sh) available for ports. Take a look:
https://github.com/phoenix-rtos/phoenix-rtos-ports/blob/7c6793d75d5b3e92e309a232c7d37ca893035aec/build.subr

Example usage:

b_port_download "https://www.lua.org/ftp/" "${archive_filename}"

You can use them now if you want or leave that for later (all ports will be refactored some day).

do_run(my_pid);

+#ifdef NOMMU
+ memset(names, 0, sizeof(struct name_entry) * num_files);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed on NOMMU targets? Doesn't the "work thread" exit after returning from thread_work()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fs_mark can run multiple loops with each calling thread_work(), so I had to reinitialize this array back to zero's after each loop

*/
df_full = get_df_full(child_tasks[0].test_dir);

+ usleep(100000);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed? Is this related to console output being interleaved with something else?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a problem with parts of logs being lost, so I used this sleep just for now to make it work.

+ #undef MAX_NAME_PATH
+
+ #define MAX_IO_BUFFER_SIZE (1024 * 32) /* Max write buffer size is 32KB */
+ #define MAX_NAME_PATH (200) /* Length of the pathname before the leaf */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess that you are trying to avoid huge static allocations on low-RAM targets. NOMMU option itself doesn't imply that the target device has a tiny pool of RAM.

I think the most flexible solution is to use calloc(), as is the case with struct name_entry *names. The behavior would remain the same (use DEFAULT_IO_SIZE==(16 * 1024) bytes), but the problem of static allocation vanishes. Also, it seems to be a simple fix: change io_buffer into a pointer and replace memset(io_buffer, 0, io_buffer_size); with a call to calloc(). Freeing the memory is not of concern, because the author already ignores that part (it would be important if "worker threads" used threads instead of forked children).

When it comes to MAX_NAME_PATH and FILENAME_SIZE, you can use defines from <limits.h>: PATH_MAX and NAME_MAX. They are defined per-architecture and seem to be perfect for this use case. (See: libphoenix/include/arch/*/limits.h)

int do_fill_fs = 0; /* Run until the file system is full */
int verbose_stats = 0; /* Print complete stats for each system call */
-char log_file_name[PATH_MAX] = "fs_log.txt"; /* Log file name for run */
+char log_file_name[PATH_MAX - 16] = "fs_log.txt"; /* Log file name for run, reserve space for suffix */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You subtract 16 to accommodate for PID suffix appended in a few places in the source file? If so, please include that information in the comment to make it clear why it is changed (i.e. that fs_mark is flaky and you fix their own bugs) and note that there is
strncpy(log_file_name, optarg, PATH_MAX);
in -l option handling code which also has to be changed.


+#ifdef NOMMU
+ #define FORK vfork
+ file_count = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is file_count = 0 needed on NOMMU targets?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

names and file_count are two variables that I need to reset after each loop, because NOMMU use vfork() to run thread_work()

+
for (i = 0; i < num_threads; i++) {
- if ((child_tasks[i].child_pid = fork()) == -1) {
+ if ((child_tasks[i].child_pid = FORK()) == -1) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using vfork() actually defeats the whole purpose of running fs_mark with multiple "child tasks", i.e. concurrent operations on files. vfork(), as opposed to fork(), causes the parent to suspend execution until its vforked child exits or execs, so every "child task" is executed sequentially.

I don't see any test commands (phoenix-rtos/phoenix-rtos-tests#233) to use more than one thread, so maybe this can be left unimplemented for now on NOMMU targets. fs_mark could use actual threads (via pthreads) instead of forking, but there are so many globals that refactoring would be quite cumbersome.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make it work with threads instead of processes on NOMMU can be a tedious task, so I wanted to make it run with just a 1 thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants