Re: [PATCH v8] rtems-debugger: Fixed 32bit pointers
looks good to me On Fri, May 14, 2021 at 11:57 AM Stephen Clark wrote: > > Using 32bit types like uint32_t for pointers creates issues on 64 bit > architectures like AArch64. Replaced occurrences of these with > uintptr_t, which will work for both 32 and 64 bit architectures. Added > hex_decode_addr function to rtems-debugger. > --- > cpukit/libdebugger/rtems-debugger-server.c | 32 ++ > cpukit/libdebugger/rtems-debugger-target.c | 2 +- > cpukit/libdebugger/rtems-debugger-target.h | 2 +- > 3 files changed, 28 insertions(+), 8 deletions(-) > > diff --git a/cpukit/libdebugger/rtems-debugger-server.c > b/cpukit/libdebugger/rtems-debugger-server.c > index 975ec23a30..9de9421b6b 100644 > --- a/cpukit/libdebugger/rtems-debugger-server.c > +++ b/cpukit/libdebugger/rtems-debugger-server.c > @@ -154,6 +154,26 @@ hex_encode(int val) >return "0123456789abcdef"[val & 0xf]; > } > > +static inline uintptr_t > +hex_decode_addr(const uint8_t* data) > +{ > + uintptr_t ui = 0; > + size_t i; > + if (data[0] == '-') { > +if (data[1] == '1') > + ui = (uintptr_t) -1; > + } > + else { > +for (i = 0; i < (sizeof(ui) * 2); ++i) { > + int v = hex_decode(data[i]); > + if (v < 0) > +break; > + ui = (ui << 4) | v; > +} > + } > + return ui; > +} > + > static inline DB_UINT > hex_decode_uint(const uint8_t* data) > { > @@ -1438,10 +1458,10 @@ remote_read_memory(uint8_t* buffer, int size) >if (comma == NULL) > remote_packet_out_str(r_E01); >else { > -DB_UINT addr; > +uintptr_t addr; > DB_UINT length; > int r; > -addr = hex_decode_uint([1]); > +addr = hex_decode_addr([1]); > length = hex_decode_uint((const uint8_t*) comma + 1); > remote_packet_out_reset(); > r = rtems_debugger_target_start_memory_access(); > @@ -1468,10 +1488,10 @@ remote_write_memory(uint8_t* buffer, int size) >comma = strchr((const char*) buffer, ','); >colon = strchr((const char*) buffer, ':'); >if (comma != NULL && colon != NULL) { > -DB_UINT addr; > +uintptr_t addr; > DB_UINT length; > int r; > -addr = hex_decode_uint([1]); > +addr = hex_decode_addr([1]); > length = hex_decode_uint((const uint8_t*) comma + 1); > r = rtems_debugger_target_start_memory_access(); > if (r == 0) { > @@ -1519,9 +1539,9 @@ remote_breakpoints(bool insert, uint8_t* buffer, int > size) > comma2 = strchr(comma1 + 1, ','); > if (comma2 != NULL) { >uint32_t capabilities; > - DB_UINT addr; > + uintptr_t addr; >DB_UINT kind; > - addr = hex_decode_uint((const uint8_t*) comma1 + 1); > + addr = hex_decode_addr((const uint8_t*) comma1 + 1); >kind = hex_decode_uint((const uint8_t*)comma2 + 1); >capabilities = rtems_debugger_target_capabilities(); >switch (buffer[1]) { > diff --git a/cpukit/libdebugger/rtems-debugger-target.c > b/cpukit/libdebugger/rtems-debugger-target.c > index bf7579700d..34e4e84d2f 100644 > --- a/cpukit/libdebugger/rtems-debugger-target.c > +++ b/cpukit/libdebugger/rtems-debugger-target.c > @@ -168,7 +168,7 @@ rtems_debugger_target_reg_table_size(void) > } > > int > -rtems_debugger_target_swbreak_control(bool insert, DB_UINT addr, DB_UINT > kind) > +rtems_debugger_target_swbreak_control(bool insert, uintptr_t addr, DB_UINT > kind) > { >rtems_debugger_target* target = rtems_debugger->target; >rtems_debugger_target_swbreak* swbreaks; > diff --git a/cpukit/libdebugger/rtems-debugger-target.h > b/cpukit/libdebugger/rtems-debugger-target.h > index f2abbe5fd3..db356e1f07 100644 > --- a/cpukit/libdebugger/rtems-debugger-target.h > +++ b/cpukit/libdebugger/rtems-debugger-target.h > @@ -200,7 +200,7 @@ extern void > rtems_debugger_target_exception_print(CPU_Exception_frame* frame); > * Software breakpoints. These are also referred to as memory breakpoints. > */ > extern int rtems_debugger_target_swbreak_control(boolinsert, > - DB_UINT addr, > + uintptr_t addr, > DB_UINT kind); > > /** > -- > 2.27.0 > > ___ > devel mailing list > devel@rtems.org > http://lists.rtems.org/mailman/listinfo/devel ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel
Re: [PATCH] score: Add and use _Per_CPU_Is_ISR_in_progress()
ok On Fri, May 14, 2021 at 9:36 AM Sebastian Huber wrote: > > Add _Per_CPU_Is_ISR_in_progress() as an optimized version of > _ISR_Is_in_progress(). > --- > cpukit/include/rtems/score/isr.h | 12 > cpukit/include/rtems/score/isrlevel.h | 11 +++ > cpukit/include/rtems/score/percpu.h | 10 ++ > cpukit/score/src/threadrestart.c | 2 +- > 4 files changed, 22 insertions(+), 13 deletions(-) > > diff --git a/cpukit/include/rtems/score/isr.h > b/cpukit/include/rtems/score/isr.h > index 3c6a9f1e2c..47c24f3a72 100644 > --- a/cpukit/include/rtems/score/isr.h > +++ b/cpukit/include/rtems/score/isr.h > @@ -147,18 +147,6 @@ void _ISR_Handler_initialization ( void ); > */ > void _ISR_Handler( void ); > > -/** > - * @brief Checks if an ISR in progress. > - * > - * This function returns true if the processor is currently servicing > - * and interrupt and false otherwise. A return value of true indicates > - * that the caller is an interrupt service routine, NOT a thread. > - * > - * @retval true Returns true when called from an ISR. > - * @retval false Returns false when not called from an ISR. > - */ > -bool _ISR_Is_in_progress( void ); > - > #ifdef __cplusplus > } > #endif > diff --git a/cpukit/include/rtems/score/isrlevel.h > b/cpukit/include/rtems/score/isrlevel.h > index 3981f2c688..d578a32c48 100644 > --- a/cpukit/include/rtems/score/isrlevel.h > +++ b/cpukit/include/rtems/score/isrlevel.h > @@ -144,6 +144,17 @@ typedef uint32_t ISR_Level; > RTEMS_COMPILER_MEMORY_BARRIER(); \ >} while (0) > > +/** > + * @brief Checks if an ISR in progress. > + * > + * This function returns true, if the processor is currently servicing > + * and interrupt, and false otherwise. A return value of true indicates > + * that the caller is an interrupt service routine, **not** a thread. > + * > + * @return true Returns true, if called from within an ISR, otherwise false. > + */ > +bool _ISR_Is_in_progress( void ); > + > /** @} */ > > #ifdef __cplusplus > diff --git a/cpukit/include/rtems/score/percpu.h > b/cpukit/include/rtems/score/percpu.h > index 58a89ec7a9..1aed17ab19 100644 > --- a/cpukit/include/rtems/score/percpu.h > +++ b/cpukit/include/rtems/score/percpu.h > @@ -683,6 +683,16 @@ static inline struct _Thread_Control > *_Per_CPU_Get_executing( >return cpu->executing; > } > > +static inline bool _Per_CPU_Is_ISR_in_progress( const Per_CPU_Control *cpu ) > +{ > +#if CPU_PROVIDES_ISR_IS_IN_PROGRESS == TRUE > + (void) cpu; > + return _ISR_Is_in_progress(); > +#else > + return cpu->isr_nest_level != 0; > +#endif > +} > + > static inline bool _Per_CPU_Is_processor_online( >const Per_CPU_Control *cpu > ) > diff --git a/cpukit/score/src/threadrestart.c > b/cpukit/score/src/threadrestart.c > index 7a1c8e4635..c8f7f7b6b1 100644 > --- a/cpukit/score/src/threadrestart.c > +++ b/cpukit/score/src/threadrestart.c > @@ -538,7 +538,7 @@ Status_Control _Thread_Restart( > >if ( > the_thread == _Per_CPU_Get_executing( cpu_self ) && > -!_ISR_Is_in_progress() > +!_Per_CPU_Is_ISR_in_progress( cpu_self ) >) { > ignored_life_states = THREAD_LIFE_PROTECTED | > THREAD_LIFE_CHANGE_DEFERRED; >} else { > -- > 2.26.2 > > ___ > devel mailing list > devel@rtems.org > http://lists.rtems.org/mailman/listinfo/devel ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel
Re: [PATCH] score: Improve parameters in _Thread_Change_life()
thanks, looks good On Fri, May 14, 2021 at 9:05 AM Sebastian Huber wrote: > > --- > cpukit/include/rtems/score/threadimpl.h | 22 ++- > cpukit/score/src/threadrestart.c| 29 +++-- > 2 files changed, 29 insertions(+), 22 deletions(-) > > diff --git a/cpukit/include/rtems/score/threadimpl.h > b/cpukit/include/rtems/score/threadimpl.h > index 44785cd937..1a5e391677 100644 > --- a/cpukit/include/rtems/score/threadimpl.h > +++ b/cpukit/include/rtems/score/threadimpl.h > @@ -297,18 +297,20 @@ Status_Control _Thread_Restart( > void _Thread_Yield( Thread_Control *executing ); > > /** > - * @brief Changes the currently executing thread to a new state with the > sets. > + * @brief Changes the life of currently executing thread. > * > - * @param clear States to clear. > - * @param set States to set. > - * @param ignore States to ignore. > + * @param life_states_to_clear are the thread life states to clear. > * > - * @return The previous state the thread was in. > + * @param life_states_to_set are the thread life states to set. > + * > + * @param ignored_life_states are the ignored thread life states. > + * > + * @return Returns the thread life state before the changes. > */ > Thread_Life_state _Thread_Change_life( > - Thread_Life_state clear, > - Thread_Life_state set, > - Thread_Life_state ignore > + Thread_Life_state life_states_to_clear, > + Thread_Life_state life_states_to_set, > + Thread_Life_state ignored_life_states > ); > > /** > @@ -338,12 +340,12 @@ void _Thread_Kill_zombies( void ); > * @brief Exits the currently executing thread. > * > * @param[in, out] executing The currently executing thread. > - * @param set The states to set. > + * @param life_states_to_set The states to set. > * @param[out] exit_value Contains the exit value of the thread. > */ > void _Thread_Exit( >Thread_Control*executing, > - Thread_Life_state set, > + Thread_Life_state life_states_to_set, >void *exit_value > ); > > diff --git a/cpukit/score/src/threadrestart.c > b/cpukit/score/src/threadrestart.c > index 775f1c7a70..7a1c8e4635 100644 > --- a/cpukit/score/src/threadrestart.c > +++ b/cpukit/score/src/threadrestart.c > @@ -197,9 +197,9 @@ void _Thread_Kill_zombies( void ) > > static Thread_Life_state _Thread_Change_life_locked( >Thread_Control*the_thread, > - Thread_Life_state clear, > - Thread_Life_state set, > - Thread_Life_state ignore > + Thread_Life_state life_states_to_clear, > + Thread_Life_state life_states_to_set, > + Thread_Life_state ignored_life_states > ) > { >Thread_Life_state previous; > @@ -207,11 +207,11 @@ static Thread_Life_state _Thread_Change_life_locked( > >previous = the_thread->Life.state; >state = previous; > - state &= ~clear; > - state |= set; > + state &= ~life_states_to_clear; > + state |= life_states_to_set; >the_thread->Life.state = state; > > - state &= ~ignore; > + state &= ~ignored_life_states; > >if ( > _Thread_Is_life_change_allowed( state ) > @@ -491,7 +491,7 @@ void _Thread_Close( > > void _Thread_Exit( >Thread_Control*executing, > - Thread_Life_state set, > + Thread_Life_state life_states_to_set, >void *exit_value > ) > { > @@ -510,7 +510,7 @@ void _Thread_Exit( >_Thread_Change_life_locked( > executing, > 0, > -set, > +life_states_to_set, > THREAD_LIFE_PROTECTED | THREAD_LIFE_CHANGE_DEFERRED >); >_Thread_State_release( executing, _context ); > @@ -583,9 +583,9 @@ Status_Control _Thread_Restart( > } > > Thread_Life_state _Thread_Change_life( > - Thread_Life_state clear, > - Thread_Life_state set, > - Thread_Life_state ignore > + Thread_Life_state life_states_to_clear, > + Thread_Life_state life_states_to_set, > + Thread_Life_state ignored_life_states > ) > { >ISR_lock_Context lock_context; > @@ -595,7 +595,12 @@ Thread_Life_state _Thread_Change_life( > >executing = _Thread_State_acquire_for_executing( _context ); > > - previous = _Thread_Change_life_locked( executing, clear, set, ignore ); > + previous = _Thread_Change_life_locked( > +executing, > +life_states_to_clear, > +life_states_to_set, > +ignored_life_states > + ); > >cpu_self = _Thread_Dispatch_disable_critical( _context ); >_Thread_State_release( executing, _context ); > -- > 2.26.2 > > ___ > devel mailing list > devel@rtems.org > http://lists.rtems.org/mailman/listinfo/devel ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel
[PATCH v8] rtems-debugger: Fixed 32bit pointers
Using 32bit types like uint32_t for pointers creates issues on 64 bit architectures like AArch64. Replaced occurrences of these with uintptr_t, which will work for both 32 and 64 bit architectures. Added hex_decode_addr function to rtems-debugger. --- cpukit/libdebugger/rtems-debugger-server.c | 32 ++ cpukit/libdebugger/rtems-debugger-target.c | 2 +- cpukit/libdebugger/rtems-debugger-target.h | 2 +- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/cpukit/libdebugger/rtems-debugger-server.c b/cpukit/libdebugger/rtems-debugger-server.c index 975ec23a30..9de9421b6b 100644 --- a/cpukit/libdebugger/rtems-debugger-server.c +++ b/cpukit/libdebugger/rtems-debugger-server.c @@ -154,6 +154,26 @@ hex_encode(int val) return "0123456789abcdef"[val & 0xf]; } +static inline uintptr_t +hex_decode_addr(const uint8_t* data) +{ + uintptr_t ui = 0; + size_t i; + if (data[0] == '-') { +if (data[1] == '1') + ui = (uintptr_t) -1; + } + else { +for (i = 0; i < (sizeof(ui) * 2); ++i) { + int v = hex_decode(data[i]); + if (v < 0) +break; + ui = (ui << 4) | v; +} + } + return ui; +} + static inline DB_UINT hex_decode_uint(const uint8_t* data) { @@ -1438,10 +1458,10 @@ remote_read_memory(uint8_t* buffer, int size) if (comma == NULL) remote_packet_out_str(r_E01); else { -DB_UINT addr; +uintptr_t addr; DB_UINT length; int r; -addr = hex_decode_uint([1]); +addr = hex_decode_addr([1]); length = hex_decode_uint((const uint8_t*) comma + 1); remote_packet_out_reset(); r = rtems_debugger_target_start_memory_access(); @@ -1468,10 +1488,10 @@ remote_write_memory(uint8_t* buffer, int size) comma = strchr((const char*) buffer, ','); colon = strchr((const char*) buffer, ':'); if (comma != NULL && colon != NULL) { -DB_UINT addr; +uintptr_t addr; DB_UINT length; int r; -addr = hex_decode_uint([1]); +addr = hex_decode_addr([1]); length = hex_decode_uint((const uint8_t*) comma + 1); r = rtems_debugger_target_start_memory_access(); if (r == 0) { @@ -1519,9 +1539,9 @@ remote_breakpoints(bool insert, uint8_t* buffer, int size) comma2 = strchr(comma1 + 1, ','); if (comma2 != NULL) { uint32_t capabilities; - DB_UINT addr; + uintptr_t addr; DB_UINT kind; - addr = hex_decode_uint((const uint8_t*) comma1 + 1); + addr = hex_decode_addr((const uint8_t*) comma1 + 1); kind = hex_decode_uint((const uint8_t*)comma2 + 1); capabilities = rtems_debugger_target_capabilities(); switch (buffer[1]) { diff --git a/cpukit/libdebugger/rtems-debugger-target.c b/cpukit/libdebugger/rtems-debugger-target.c index bf7579700d..34e4e84d2f 100644 --- a/cpukit/libdebugger/rtems-debugger-target.c +++ b/cpukit/libdebugger/rtems-debugger-target.c @@ -168,7 +168,7 @@ rtems_debugger_target_reg_table_size(void) } int -rtems_debugger_target_swbreak_control(bool insert, DB_UINT addr, DB_UINT kind) +rtems_debugger_target_swbreak_control(bool insert, uintptr_t addr, DB_UINT kind) { rtems_debugger_target* target = rtems_debugger->target; rtems_debugger_target_swbreak* swbreaks; diff --git a/cpukit/libdebugger/rtems-debugger-target.h b/cpukit/libdebugger/rtems-debugger-target.h index f2abbe5fd3..db356e1f07 100644 --- a/cpukit/libdebugger/rtems-debugger-target.h +++ b/cpukit/libdebugger/rtems-debugger-target.h @@ -200,7 +200,7 @@ extern void rtems_debugger_target_exception_print(CPU_Exception_frame* frame); * Software breakpoints. These are also referred to as memory breakpoints. */ extern int rtems_debugger_target_swbreak_control(boolinsert, - DB_UINT addr, + uintptr_t addr, DB_UINT kind); /** -- 2.27.0 ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel
[PATCH v4 4/5] psx13: Added tests for utimensat() and futimens()
Improved tests for utime() and utimes() and update license. Close #4399 --- testsuites/psxtests/psx13/main.c | 5 +- testsuites/psxtests/psx13/test.c | 499 +-- 2 files changed, 481 insertions(+), 23 deletions(-) diff --git a/testsuites/psxtests/psx13/main.c b/testsuites/psxtests/psx13/main.c index f9e7907..7a560f9 100644 --- a/testsuites/psxtests/psx13/main.c +++ b/testsuites/psxtests/psx13/main.c @@ -1,5 +1,3 @@ -/* SPDX-License-Identifier: BSD-2-Clause */ - /** * @file * @@ -8,8 +6,7 @@ */ /* - * COPYRIGHT (c) 1989-2009, 2021. - * On-Line Applications Research Corporation (OAR). + * COPYRIGHT (C) 1989, 2021 On-Line Applications Research Corporation (OAR). * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/testsuites/psxtests/psx13/test.c b/testsuites/psxtests/psx13/test.c index e98b03a..0754dbc 100644 --- a/testsuites/psxtests/psx13/test.c +++ b/testsuites/psxtests/psx13/test.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: BSD-2-Clause */ +/* SPDX-License-Identifier: BSD-2-Clause */ /** * @file @@ -17,12 +17,13 @@ * - umask() * - utime() * - utimes() + * - utimensat() + * - futimens() * - sync() */ /* - * COPYRIGHT (c) 1989-2009, 2021. - * On-Line Applications Research Corporation (OAR). + * COPYRIGHT (C) 1989, 2021 On-Line Applications Research Corporation (OAR). * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -52,6 +53,8 @@ #include #include +#include +#include #include #include #include @@ -210,8 +213,7 @@ static void Dup2Test( void ) } /** - * @brief Exercises fdatasync(). Does NOT test the functionality of the - *underlying fdatasync entry in the IMFS op table. + * @brief Exercises fdatasync(). */ static void FDataSyncTest( void ) { @@ -259,60 +261,517 @@ static void UMaskTest( void ) } /** - * @brief Exercises utime(). Does not test the functionality of the - *underlying utime entry in the IMFS op table. + * @brief Exercises utime(). */ static void UTimeTest( void ) { int rv; struct utimbuf time; + struct timespec current_time; struct stat fstat; - /* First, an invalid filename. */ + /* ENOENT test case */ + + /* Case: Pass an invalid filename. */ rv = utime( "!This is an =invalid p@thname!!! :)", NULL ); rtems_test_assert( rv == -1 ); rtems_test_assert( errno == ENOENT ); - /* Now, the success test. */ + /* EACCES test case */ + + /* Case: Change user ID to someone besides root */ + rv = seteuid( 1 ); + rtems_test_assert( rv == 0 ); + + rv = utime( "testfile1.tst", NULL ); + rtems_test_assert( rv == -1 ); + rtems_test_assert( errno == EACCES ); + + rv = seteuid( 0 ); + rtems_test_assert( rv == 0 ); + + /* EINVAL test cases */ + + /* Case: Invalid access time */ + time.actime = -1; + time.modtime = 54321; + + rv = utime( "testfile1.tst", ); + rtems_test_assert( rv == -1 ); + rtems_test_assert( errno == EINVAL ); + + /* Case: Invalid modified time */ + time.actime = 12345; + time.modtime = -1; + + rv = utime( "testfile1.tst", ); + rtems_test_assert( rv == -1 ); + rtems_test_assert( errno == EINVAL ); + + /* Successful test cases */ + + /* Case: Test without times argument */ + clock_gettime( CLOCK_REALTIME, _time ); + + rv = utime( "testfile1.tst", NULL ); + rtems_test_assert( rv == 0 ); + + rv = stat( "testfile1.tst", ); + rtems_test_assert( rv == 0 ); + rtems_test_assert( current_time.tv_sec <= fstat.st_atim.tv_sec ); + rtems_test_assert( current_time.tv_sec <= fstat.st_mtim.tv_sec ); + + /* Case: time is filled with valid values */ time.actime = 12345; time.modtime = 54321; rv = utime( "testfile1.tst", ); rtems_test_assert( rv == 0 ); - /* But, did it set the time? */ + /* Check that it actually changed the time */ rv = stat( "testfile1.tst", ); rtems_test_assert( rv == 0 ); rtems_test_assert( fstat.st_atime == 12345 ); rtems_test_assert( fstat.st_mtime == 54321 ); - - rv = utime( "testfile1.tst", NULL ); - rtems_test_assert( rv == 0 ); } /** - * @brief Exercises utimes(). Does NOT test the functionality of the - *underlying utime entry in the IMFS op table. + * @brief Exercises utimes(). */ static void UTimesTest( void ) { int rv; struct timeval time[2]; + struct timespec current_time; struct stat fstat; - /* First, an invalid filename. */ + /* ENOENT test case */ + + /* Case: First, an invalid filename. */ rv = utimes( "!This is an =invalid p@thname!!! : )", NULL); rtems_test_assert( rv == -1 ); rtems_test_assert( errno == ENOENT ); - /* Now, the success test. */ + /* EACCES test case */ + + /* Change the user ID of the process to someone besides root */ + rv = seteuid( 1 ); + rtems_test_assert( rv ==
[PATCH v4 5/5] Change filesystem utime_h handler to utimens_h
Also updated licenses. Closes #4400 --- bsps/arm/csb337/umon/tfsDriver.c| 2 +- cpukit/Makefile.am | 4 +- cpukit/include/rtems/confdefs/libio.h | 4 +- cpukit/include/rtems/imfs.h | 35 - cpukit/include/rtems/libio.h| 55 +-- cpukit/libcsupport/src/__usrenv.c | 39 +-- cpukit/libcsupport/src/futimens.c | 2 +- cpukit/libcsupport/src/utimensat.c | 2 +- cpukit/libfs/src/defaults/default_ops.c | 34 - cpukit/libfs/src/defaults/default_utime.c | 32 cpukit/libfs/src/defaults/default_utimens.c | 49 cpukit/libfs/src/dosfs/msdos_init.c | 48 cpukit/libfs/src/ftpfs/ftpfs.c | 44 -- cpukit/libfs/src/ftpfs/tftpDriver.c | 28 +++--- cpukit/libfs/src/imfs/imfs_init.c | 30 --- cpukit/libfs/src/imfs/imfs_utime.c | 41 cpukit/libfs/src/imfs/imfs_utimens.c| 58 + cpukit/libfs/src/jffs2/src/fs-rtems.c | 11 +++--- cpukit/libfs/src/rfs/rtems-rfs-rtems.c | 16 spec/build/cpukit/librtemscpu.yml | 4 +- 20 files changed, 345 insertions(+), 193 deletions(-) delete mode 100644 cpukit/libfs/src/defaults/default_utime.c create mode 100644 cpukit/libfs/src/defaults/default_utimens.c delete mode 100644 cpukit/libfs/src/imfs/imfs_utime.c create mode 100644 cpukit/libfs/src/imfs/imfs_utimens.c diff --git a/bsps/arm/csb337/umon/tfsDriver.c b/bsps/arm/csb337/umon/tfsDriver.c index 0195346..caf3a4b 100644 --- a/bsps/arm/csb337/umon/tfsDriver.c +++ b/bsps/arm/csb337/umon/tfsDriver.c @@ -657,7 +657,7 @@ static const rtems_filesystem_operations_table rtems_tfs_ops = { .mount_h = rtems_filesystem_default_mount, .unmount_h = rtems_filesystem_default_unmount, .fsunmount_me_h = rtems_filesystem_default_fsunmount, - .utime_h = rtems_filesystem_default_utime, + .utimens_h = rtems_filesystem_default_utimens, .symlink_h = rtems_filesystem_default_symlink, .readlink_h = rtems_filesystem_default_readlink, .rename_h = rtems_filesystem_default_rename, diff --git a/cpukit/Makefile.am b/cpukit/Makefile.am index 29b4207..c144773 100644 --- a/cpukit/Makefile.am +++ b/cpukit/Makefile.am @@ -377,7 +377,7 @@ librtemscpu_a_SOURCES += libfs/src/defaults/default_rmnod.c librtemscpu_a_SOURCES += libfs/src/defaults/default_statvfs.c librtemscpu_a_SOURCES += libfs/src/defaults/default_symlink.c librtemscpu_a_SOURCES += libfs/src/defaults/default_unmount.c -librtemscpu_a_SOURCES += libfs/src/defaults/default_utime.c +librtemscpu_a_SOURCES += libfs/src/defaults/default_utimens.c librtemscpu_a_SOURCES += libfs/src/defaults/default_write.c librtemscpu_a_SOURCES += libfs/src/defaults/default_writev.c librtemscpu_a_SOURCES += libfs/src/dosfs/fat.c @@ -434,7 +434,7 @@ librtemscpu_a_SOURCES += libfs/src/imfs/imfs_stat.c librtemscpu_a_SOURCES += libfs/src/imfs/imfs_stat_file.c librtemscpu_a_SOURCES += libfs/src/imfs/imfs_symlink.c librtemscpu_a_SOURCES += libfs/src/imfs/imfs_unmount.c -librtemscpu_a_SOURCES += libfs/src/imfs/imfs_utime.c +librtemscpu_a_SOURCES += libfs/src/imfs/imfs_utimens.c librtemscpu_a_SOURCES += libfs/src/imfs/ioman.c librtemscpu_a_SOURCES += libfs/src/pipe/fifo.c librtemscpu_a_SOURCES += libfs/src/pipe/pipe.c diff --git a/cpukit/include/rtems/confdefs/libio.h b/cpukit/include/rtems/confdefs/libio.h index 16a4fb69..1b84f8c 100644 --- a/cpukit/include/rtems/confdefs/libio.h +++ b/cpukit/include/rtems/confdefs/libio.h @@ -231,9 +231,9 @@ static const rtems_filesystem_operations_table IMFS_root_ops = { #endif rtems_filesystem_default_fsunmount, #ifdef CONFIGURE_IMFS_DISABLE_UTIME -rtems_filesystem_default_utime, +rtems_filesystem_default_utimens, #else -IMFS_utime, +IMFS_utimens, #endif #ifdef CONFIGURE_IMFS_DISABLE_SYMLINK rtems_filesystem_default_symlink, diff --git a/cpukit/include/rtems/imfs.h b/cpukit/include/rtems/imfs.h index b2a9868..57c498c 100644 --- a/cpukit/include/rtems/imfs.h +++ b/cpukit/include/rtems/imfs.h @@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + /** * @file * @@ -5,12 +7,28 @@ */ /* - * COPYRIGHT (c) 1989-2011. - * On-Line Applications Research Corporation (OAR). - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. + * COPYRIGHT (C) 1989, 2021 On-Line Applications Research Corporation (OAR). + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + *notice, this list of conditions and the following disclaimer. +
[PATCH v4 1/5] libcsupport: Added futimens() and utimensat()
Created futimens.c and utimensat.c to add support for the POSIX methods futimens() and utimensat(). utime() and utimes() are considered obsolote by POSIX, but RTEMS will continue to support them. Closes #4396 --- cpukit/Makefile.am | 2 + cpukit/include/rtems/libio_.h| 95 +++-- cpukit/include/rtems/score/timespec.h| 44 +- cpukit/libcsupport/src/futimens.c| 87 cpukit/libcsupport/src/utimensat.c | 225 +++ cpukit/score/src/timespecisnonnegative.c | 54 spec/build/cpukit/librtemscpu.yml| 3 + 7 files changed, 495 insertions(+), 15 deletions(-) create mode 100644 cpukit/libcsupport/src/futimens.c create mode 100644 cpukit/libcsupport/src/utimensat.c create mode 100644 cpukit/score/src/timespecisnonnegative.c diff --git a/cpukit/Makefile.am b/cpukit/Makefile.am index b0df610..29b4207 100644 --- a/cpukit/Makefile.am +++ b/cpukit/Makefile.am @@ -262,6 +262,8 @@ librtemscpu_a_SOURCES += libcsupport/src/unmount.c librtemscpu_a_SOURCES += libcsupport/src/__usrenv.c librtemscpu_a_SOURCES += libcsupport/src/utime.c librtemscpu_a_SOURCES += libcsupport/src/utimes.c +librtemscpu_a_SOURCES += libcsupport/src/futimens.c +librtemscpu_a_SOURCES += libcsupport/src/utimensat.c librtemscpu_a_SOURCES += libcsupport/src/utsname.c librtemscpu_a_SOURCES += libcsupport/src/vprintk.c librtemscpu_a_SOURCES += libcsupport/src/write.c diff --git a/cpukit/include/rtems/libio_.h b/cpukit/include/rtems/libio_.h index e9eb462..26d6c1e 100644 --- a/cpukit/include/rtems/libio_.h +++ b/cpukit/include/rtems/libio_.h @@ -1,23 +1,42 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + /** * @file * * @brief LibIO Internal Interface - * + * * This file is the libio internal interface. */ /* - * COPYRIGHT (c) 1989-2011. - * On-Line Applications Research Corporation (OAR). + * COPYRIGHT (C) 1989, 2021 On-Line Applications Research Corporation (OAR). * - * Modifications to support reference counting in the file system are - * Copyright (c) 2012 embedded brains GmbH. + * Modifications to support reference counting in the file system are + * Copyright (c) 2012 embedded brains GmbH. * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + *notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + *notice, this list of conditions and the following disclaimer in the + *documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. */ + #ifndef _RTEMS_RTEMS_LIBIO__H #define _RTEMS_RTEMS_LIBIO__H @@ -30,6 +49,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" { @@ -357,6 +377,65 @@ static inline void rtems_filesystem_instance_unlock( (*mt_entry->ops->unlock_h)( mt_entry ); } +/** + * @brief Checks the tv_nsec member of a timespec struct + * + * This function is used with utimensat() and futimens() only. This ensures + * that the value in the tv_nsec member is equal to either UTIME_NOW, + * UTIME_OMIT, or a value greater-than or equal to zero and less than a + * billion. + * + * @param[in] time The timespec struct to be validated + * + * @retval true The tv_nsec member is a valid value. + * @retval false The tv_nsec member is not a valid value. + */ +bool rtems_filesystem_utime_tv_nsec_valid( struct timespec time ); + +/** + * @brief Checks for errors and if the process has write permissions to the file. + * + * This function is only used with utimensat() and futimens().It checks for + * EACCES and EPERM errors depending on what values are in @a times and if the + * process has write permissions to the file. + * + * @param[in] currentloc The current location to a file + * @param[in] times The timespecs used to check for errors. The
[PATCH v4 3/5] libcsupport: Implement utimes() in terms of utimensat()
utimes() now calls utimensat() to update file access and modification timestamps. Updated license. Closes #4398 --- cpukit/libcsupport/src/utimes.c | 62 - 1 file changed, 49 insertions(+), 13 deletions(-) diff --git a/cpukit/libcsupport/src/utimes.c b/cpukit/libcsupport/src/utimes.c index 3dc47c0..0ff6662 100644 --- a/cpukit/libcsupport/src/utimes.c +++ b/cpukit/libcsupport/src/utimes.c @@ -1,38 +1,74 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + /** * @file * - * @brief Change File Last Access and Modification Times * @ingroup libcsupport + * + * @brief Set file access and modification times in milliseconds. */ /* - * Written by: Vinu Rajashekhar + * COPYRIGHT (C) 1989, 2021 On-Line Applications Research Corporation (OAR). * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + *notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + *notice, this list of conditions and the following disclaimer in the + *documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. */ #ifdef HAVE_CONFIG_H #include "config.h" #endif -#include -#include #include +#include + +#include +/** + * https://pubs.opengroup.org/onlinepubs/9699919799.2008edition/functions/futimens.html + * + * Set file access and modification times + */ int utimes( const char *path, const struct timeval times[2] -) +) { - struct utimbuf timeinsecs; + struct timespec new_times[2]; if ( times == NULL ) -return utime( path, NULL ); + { +return utimensat( AT_FDCWD, path, NULL , 0 ); + } - timeinsecs.actime = times[0].tv_sec; - timeinsecs.modtime = times[1].tv_sec; + _Timespec_Set( +_times[0], +times[0].tv_sec, +times[0].tv_usec * TOD_NANOSECONDS_PER_MICROSECOND + ); + _Timespec_Set( +_times[1], +times[1].tv_sec, +times[1].tv_usec * TOD_NANOSECONDS_PER_MICROSECOND + ); - return utime( path, ); + return utimensat( AT_FDCWD, path, new_times, 0 ); } -- 1.8.3.1 ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel
[PATCH v4 0/5] Add nanosecond support patch
Hi, Here are the patches with the requested changes. In this iteration, I: - Used timespec macros and defined constants - Updated more file copyrights - Fixed some wording - changed rtems_filesystem_utime_check_times() to rtems_filesystem_utime_update() Thanks, Ryan Ryan Long (5): libcsupport: Added futimens() and utimensat() libcsupport: Implement utime() in terms of utimensat() libcsupport: Implement utimes() in terms of utimensat() psx13: Added tests for utimensat() and futimens() Change filesystem utime_h handler to utimens_h bsps/arm/csb337/umon/tfsDriver.c| 2 +- cpukit/Makefile.am | 6 +- cpukit/include/rtems/confdefs/libio.h | 4 +- cpukit/include/rtems/imfs.h | 35 +- cpukit/include/rtems/libio.h| 55 +-- cpukit/include/rtems/libio_.h | 95 +- cpukit/include/rtems/score/timespec.h | 44 ++- cpukit/libcsupport/src/__usrenv.c | 39 ++- cpukit/libcsupport/src/futimens.c | 87 + cpukit/libcsupport/src/utime.c | 75 +++-- cpukit/libcsupport/src/utimensat.c | 225 + cpukit/libcsupport/src/utimes.c | 62 +++- cpukit/libfs/src/defaults/default_ops.c | 34 +- cpukit/libfs/src/defaults/default_utime.c | 32 -- cpukit/libfs/src/defaults/default_utimens.c | 49 +++ cpukit/libfs/src/dosfs/msdos_init.c | 48 ++- cpukit/libfs/src/ftpfs/ftpfs.c | 44 +-- cpukit/libfs/src/ftpfs/tftpDriver.c | 28 +- cpukit/libfs/src/imfs/imfs_init.c | 30 +- cpukit/libfs/src/imfs/imfs_utime.c | 41 --- cpukit/libfs/src/imfs/imfs_utimens.c| 58 cpukit/libfs/src/jffs2/src/fs-rtems.c | 11 +- cpukit/libfs/src/rfs/rtems-rfs-rtems.c | 16 +- cpukit/score/src/timespecisnonnegative.c| 54 +++ spec/build/cpukit/librtemscpu.yml | 7 +- testsuites/psxtests/psx13/main.c| 5 +- testsuites/psxtests/psx13/test.c| 499 ++-- 27 files changed, 1410 insertions(+), 275 deletions(-) create mode 100644 cpukit/libcsupport/src/futimens.c create mode 100644 cpukit/libcsupport/src/utimensat.c delete mode 100644 cpukit/libfs/src/defaults/default_utime.c create mode 100644 cpukit/libfs/src/defaults/default_utimens.c delete mode 100644 cpukit/libfs/src/imfs/imfs_utime.c create mode 100644 cpukit/libfs/src/imfs/imfs_utimens.c create mode 100644 cpukit/score/src/timespecisnonnegative.c -- 1.8.3.1 ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel
[PATCH v4 2/5] libcsupport: Implement utime() in terms of utimensat()
utime() now calls utimensat() to update file access and modification timestamps. Updated license. Closes #4397 --- cpukit/libcsupport/src/utime.c | 75 +++--- 1 file changed, 42 insertions(+), 33 deletions(-) diff --git a/cpukit/libcsupport/src/utime.c b/cpukit/libcsupport/src/utime.c index e2d8883..a42303c 100644 --- a/cpukit/libcsupport/src/utime.c +++ b/cpukit/libcsupport/src/utime.c @@ -1,58 +1,67 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + /** * @file * - * @brief Set File Access and Modification Times * @ingroup libcsupport + * + * @brief Set file access and modification times in seconds. */ /* - * COPYRIGHT (c) 1989-1999. - * On-Line Applications Research Corporation (OAR). + * COPYRIGHT (C) 1989, 2021 On-Line Applications Research Corporation (OAR). + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + *notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + *notice, this list of conditions and the following disclaimer in the + *documentation and/or other materials provided with the distribution. * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. */ #ifdef HAVE_CONFIG_H #include "config.h" #endif -/* FIXME: This include is a workaround for a broken in Newlib */ -#include +#include +#include +#include #include -#include - /** - * POSIX 1003.1b 5.5.6 - Set File Access and Modification Times + * https://pubs.opengroup.org/onlinepubs/009604599/functions/utime.html + * + * Set file access and modification times */ -int utime( const char *path, const struct utimbuf *times ) +int utime( + const char *path, + const struct utimbuf *times +) { - int rv = 0; - rtems_filesystem_eval_path_context_t ctx; - int eval_flags = RTEMS_FS_FOLLOW_LINK; - const rtems_filesystem_location_info_t *currentloc = -rtems_filesystem_eval_path_start( , path, eval_flags ); - struct utimbuf now_times; - - if ( times == NULL ) { -time_t now = time( NULL ); + struct timespec new_times[2]; -now_times.actime = now; -now_times.modtime = now; - -times = _times; + if ( times == NULL ) + { +return utimensat(AT_FDCWD, path, NULL, 0); } - rv = (*currentloc->mt_entry->ops->utime_h)( -currentloc, -times->actime, -times->modtime - ); - - rtems_filesystem_eval_path_cleanup( ); + _Timespec_Set(_times[0], times->actime, 0); + _Timespec_Set(_times[1], times->modtime, 0); - return rv; + return utimensat(AT_FDCWD, path, new_times, 0); } -- 1.8.3.1 ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel
[PATCH] score: Add and use _Per_CPU_Is_ISR_in_progress()
Add _Per_CPU_Is_ISR_in_progress() as an optimized version of _ISR_Is_in_progress(). --- cpukit/include/rtems/score/isr.h | 12 cpukit/include/rtems/score/isrlevel.h | 11 +++ cpukit/include/rtems/score/percpu.h | 10 ++ cpukit/score/src/threadrestart.c | 2 +- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/cpukit/include/rtems/score/isr.h b/cpukit/include/rtems/score/isr.h index 3c6a9f1e2c..47c24f3a72 100644 --- a/cpukit/include/rtems/score/isr.h +++ b/cpukit/include/rtems/score/isr.h @@ -147,18 +147,6 @@ void _ISR_Handler_initialization ( void ); */ void _ISR_Handler( void ); -/** - * @brief Checks if an ISR in progress. - * - * This function returns true if the processor is currently servicing - * and interrupt and false otherwise. A return value of true indicates - * that the caller is an interrupt service routine, NOT a thread. - * - * @retval true Returns true when called from an ISR. - * @retval false Returns false when not called from an ISR. - */ -bool _ISR_Is_in_progress( void ); - #ifdef __cplusplus } #endif diff --git a/cpukit/include/rtems/score/isrlevel.h b/cpukit/include/rtems/score/isrlevel.h index 3981f2c688..d578a32c48 100644 --- a/cpukit/include/rtems/score/isrlevel.h +++ b/cpukit/include/rtems/score/isrlevel.h @@ -144,6 +144,17 @@ typedef uint32_t ISR_Level; RTEMS_COMPILER_MEMORY_BARRIER(); \ } while (0) +/** + * @brief Checks if an ISR in progress. + * + * This function returns true, if the processor is currently servicing + * and interrupt, and false otherwise. A return value of true indicates + * that the caller is an interrupt service routine, **not** a thread. + * + * @return true Returns true, if called from within an ISR, otherwise false. + */ +bool _ISR_Is_in_progress( void ); + /** @} */ #ifdef __cplusplus diff --git a/cpukit/include/rtems/score/percpu.h b/cpukit/include/rtems/score/percpu.h index 58a89ec7a9..1aed17ab19 100644 --- a/cpukit/include/rtems/score/percpu.h +++ b/cpukit/include/rtems/score/percpu.h @@ -683,6 +683,16 @@ static inline struct _Thread_Control *_Per_CPU_Get_executing( return cpu->executing; } +static inline bool _Per_CPU_Is_ISR_in_progress( const Per_CPU_Control *cpu ) +{ +#if CPU_PROVIDES_ISR_IS_IN_PROGRESS == TRUE + (void) cpu; + return _ISR_Is_in_progress(); +#else + return cpu->isr_nest_level != 0; +#endif +} + static inline bool _Per_CPU_Is_processor_online( const Per_CPU_Control *cpu ) diff --git a/cpukit/score/src/threadrestart.c b/cpukit/score/src/threadrestart.c index 7a1c8e4635..c8f7f7b6b1 100644 --- a/cpukit/score/src/threadrestart.c +++ b/cpukit/score/src/threadrestart.c @@ -538,7 +538,7 @@ Status_Control _Thread_Restart( if ( the_thread == _Per_CPU_Get_executing( cpu_self ) && -!_ISR_Is_in_progress() +!_Per_CPU_Is_ISR_in_progress( cpu_self ) ) { ignored_life_states = THREAD_LIFE_PROTECTED | THREAD_LIFE_CHANGE_DEFERRED; } else { -- 2.26.2 ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel
[PATCH] score: Improve parameters in _Thread_Change_life()
--- cpukit/include/rtems/score/threadimpl.h | 22 ++- cpukit/score/src/threadrestart.c| 29 +++-- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/cpukit/include/rtems/score/threadimpl.h b/cpukit/include/rtems/score/threadimpl.h index 44785cd937..1a5e391677 100644 --- a/cpukit/include/rtems/score/threadimpl.h +++ b/cpukit/include/rtems/score/threadimpl.h @@ -297,18 +297,20 @@ Status_Control _Thread_Restart( void _Thread_Yield( Thread_Control *executing ); /** - * @brief Changes the currently executing thread to a new state with the sets. + * @brief Changes the life of currently executing thread. * - * @param clear States to clear. - * @param set States to set. - * @param ignore States to ignore. + * @param life_states_to_clear are the thread life states to clear. * - * @return The previous state the thread was in. + * @param life_states_to_set are the thread life states to set. + * + * @param ignored_life_states are the ignored thread life states. + * + * @return Returns the thread life state before the changes. */ Thread_Life_state _Thread_Change_life( - Thread_Life_state clear, - Thread_Life_state set, - Thread_Life_state ignore + Thread_Life_state life_states_to_clear, + Thread_Life_state life_states_to_set, + Thread_Life_state ignored_life_states ); /** @@ -338,12 +340,12 @@ void _Thread_Kill_zombies( void ); * @brief Exits the currently executing thread. * * @param[in, out] executing The currently executing thread. - * @param set The states to set. + * @param life_states_to_set The states to set. * @param[out] exit_value Contains the exit value of the thread. */ void _Thread_Exit( Thread_Control*executing, - Thread_Life_state set, + Thread_Life_state life_states_to_set, void *exit_value ); diff --git a/cpukit/score/src/threadrestart.c b/cpukit/score/src/threadrestart.c index 775f1c7a70..7a1c8e4635 100644 --- a/cpukit/score/src/threadrestart.c +++ b/cpukit/score/src/threadrestart.c @@ -197,9 +197,9 @@ void _Thread_Kill_zombies( void ) static Thread_Life_state _Thread_Change_life_locked( Thread_Control*the_thread, - Thread_Life_state clear, - Thread_Life_state set, - Thread_Life_state ignore + Thread_Life_state life_states_to_clear, + Thread_Life_state life_states_to_set, + Thread_Life_state ignored_life_states ) { Thread_Life_state previous; @@ -207,11 +207,11 @@ static Thread_Life_state _Thread_Change_life_locked( previous = the_thread->Life.state; state = previous; - state &= ~clear; - state |= set; + state &= ~life_states_to_clear; + state |= life_states_to_set; the_thread->Life.state = state; - state &= ~ignore; + state &= ~ignored_life_states; if ( _Thread_Is_life_change_allowed( state ) @@ -491,7 +491,7 @@ void _Thread_Close( void _Thread_Exit( Thread_Control*executing, - Thread_Life_state set, + Thread_Life_state life_states_to_set, void *exit_value ) { @@ -510,7 +510,7 @@ void _Thread_Exit( _Thread_Change_life_locked( executing, 0, -set, +life_states_to_set, THREAD_LIFE_PROTECTED | THREAD_LIFE_CHANGE_DEFERRED ); _Thread_State_release( executing, _context ); @@ -583,9 +583,9 @@ Status_Control _Thread_Restart( } Thread_Life_state _Thread_Change_life( - Thread_Life_state clear, - Thread_Life_state set, - Thread_Life_state ignore + Thread_Life_state life_states_to_clear, + Thread_Life_state life_states_to_set, + Thread_Life_state ignored_life_states ) { ISR_lock_Context lock_context; @@ -595,7 +595,12 @@ Thread_Life_state _Thread_Change_life( executing = _Thread_State_acquire_for_executing( _context ); - previous = _Thread_Change_life_locked( executing, clear, set, ignore ); + previous = _Thread_Change_life_locked( +executing, +life_states_to_clear, +life_states_to_set, +ignored_life_states + ); cpu_self = _Thread_Dispatch_disable_critical( _context ); _Thread_State_release( executing, _context ); -- 2.26.2 ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel
Re: [PATCH v3 1/5] libcsupport: Added futimens() and utimensat()
On Fri, May 14, 2021 at 8:49 AM Ryan Long wrote: > > Reply is below. > > -Original Message- > From: Gedare Bloom > Sent: Wednesday, May 12, 2021 12:34 PM > To: Ryan Long > Cc: devel@rtems.org > Subject: Re: [PATCH v3 1/5] libcsupport: Added futimens() and utimensat() > > On Wed, May 12, 2021 at 7:33 AM Ryan Long wrote: > > > > Created futimens.c and utimensat.c to add support for the POSIX > > methods futimens() and utimensat(). > > > > utime() and utimes() are considered obsolote by POSIX, but RTEMS will > > continue to support them. > > > > Closes #4396 > > --- > > cpukit/Makefile.am | 2 + > > cpukit/include/rtems/libio_.h| 64 - > > cpukit/include/rtems/score/timespec.h| 16 ++- > > cpukit/libcsupport/src/futimens.c| 87 > > cpukit/libcsupport/src/utimensat.c | 224 > > +++ > > cpukit/score/src/timespecisnonnegative.c | 35 + > > spec/build/cpukit/librtemscpu.yml| 3 + > > 7 files changed, 426 insertions(+), 5 deletions(-) create mode > > 100644 cpukit/libcsupport/src/futimens.c create mode 100644 > > cpukit/libcsupport/src/utimensat.c > > create mode 100644 cpukit/score/src/timespecisnonnegative.c > > > > diff --git a/cpukit/Makefile.am b/cpukit/Makefile.am index > > b0df610..29b4207 100644 > > --- a/cpukit/Makefile.am > > +++ b/cpukit/Makefile.am > > @@ -262,6 +262,8 @@ librtemscpu_a_SOURCES += libcsupport/src/unmount.c > > librtemscpu_a_SOURCES += libcsupport/src/__usrenv.c > > librtemscpu_a_SOURCES += libcsupport/src/utime.c > > librtemscpu_a_SOURCES += libcsupport/src/utimes.c > > +librtemscpu_a_SOURCES += libcsupport/src/futimens.c > > +librtemscpu_a_SOURCES += libcsupport/src/utimensat.c > > librtemscpu_a_SOURCES += libcsupport/src/utsname.c > > librtemscpu_a_SOURCES += libcsupport/src/vprintk.c > > librtemscpu_a_SOURCES += libcsupport/src/write.c diff --git > > a/cpukit/include/rtems/libio_.h b/cpukit/include/rtems/libio_.h index > > e9eb462..b7455ef 100644 > > --- a/cpukit/include/rtems/libio_.h > > +++ b/cpukit/include/rtems/libio_.h > > @@ -2,13 +2,12 @@ > > * @file > > * > > * @brief LibIO Internal Interface > > - * > > + * > > * This file is the libio internal interface. > > */ > > > > /* > > - * COPYRIGHT (c) 1989-2011. > > - * On-Line Applications Research Corporation (OAR). > > + * COPYRIGHT (C) 1989, 2021 On-Line Applications Research Corporation > > (OAR). > > * > > * Modifications to support reference counting in the file system are > > * Copyright (c) 2012 embedded brains GmbH. > > @@ -30,6 +29,7 @@ > > #include > > #include > > #include > > +#include > > > > #ifdef __cplusplus > > extern "C" { > > @@ -357,6 +357,64 @@ static inline void rtems_filesystem_instance_unlock( > >(*mt_entry->ops->unlock_h)( mt_entry ); } > > > > +/** > > + * @brief Checks the tv_nsec member of a timespec struct > > + * > > + * This function is used with utimensat() and futimens() only. This > > +ensures > > + * that the value in the tv_nsec member is equal to either UTIME_NOW, > > + * UTIME_OMIT, or a value greater-than or equal to zero and less than > > +a > > + * billion. > > + * > > + * @param[in] time The timespec struct to be validated > > + * > > + * @retval Returns true if tv_nsec member is a valid value, otherwise > > false. > > + */ > > +bool rtems_filesystem_utime_tv_nsec_valid( struct timespec time ); > > + > > +/** > > + * @brief Determines if the process has write permissions to a file > I think it is more specific than that. Also, missing period. > > > + * > > + * The timespec at index 0 is the access time, the timespec at index > > + 1 is the > > + * modification time. > Should this note be on the @param[in] times below? > [Ryan Long] Makes sense. I'll move it there. > > > + * > > + * This function is only used with utimensat() and futimens(). This > > + checks > > + * whether the process has write access to a file, and checks for > > + EACCES > > + * and EPERM errors depending on what values are in @times and if the > > + process > > + * has write permissions to the file. > > + * > > + * @param[in] currentloc The current location to a file > > + * @param[in] times The timespec instance that will update the > > + timestamps > update? nothing about this function seems to be an update? > [Ryan Long] I'll change this to just say something like "The timespec > instance used to check for errors". Is there another name for this function > that you think would fit better? > While it is checking for the appropriate permissions, it's also checking for > errors, so I'm not sure if this function name fits anymore. > > > + * > > + * @retval Returns 0 if the process has write permissions, otherwise -1. > > + */ > > +int rtems_filesystem_utime_check_permissions( > > + const rtems_filesystem_location_info_t *currentloc, > > + const struct timespec times[2] > > +); > > + > > +/** > > + * @brief Checks @times and fills
Re: [PATCH 2/2] rtems: Fix task restart within interrupt context
These 2 patches are fine. Although it is an internal interface, you might make the 'ignore' parameter 'ignore_mask' maybe. My initial thought when I see 'ignore' is that variable is ignored/unused, not that it contains the states to ignore. Since the function is internal and has no documentation, this might make it easier for future maintainers to understand. On Fri, May 14, 2021 at 7:11 AM Sebastian Huber wrote: > > rtems_task_restart() may be called from within interrupt context. So > checking only that the thread to restart is equal to the executing > thread is insufficient to determine a self restart. We have to also > check that no ISR is in progress. Merge _Thread_Restart_other() and > _Thread_Restart_self() into one _Thread_Restart() since they share a lot > of common code. > > Close #4412. > --- > cpukit/include/rtems/score/threadimpl.h | 15 +- > cpukit/rtems/src/taskrestart.c | 8 +-- > cpukit/score/src/threadrestart.c| 68 ++--- > 3 files changed, 17 insertions(+), 74 deletions(-) > > diff --git a/cpukit/include/rtems/score/threadimpl.h > b/cpukit/include/rtems/score/threadimpl.h > index 8674a3f2b3..44785cd937 100644 > --- a/cpukit/include/rtems/score/threadimpl.h > +++ b/cpukit/include/rtems/score/threadimpl.h > @@ -270,19 +270,6 @@ Status_Control _Thread_Start( >ISR_lock_Context *lock_context > ); > > -/** > - * @brief Restarts the currently executing thread. > - * > - * @param[in, out] executing The currently executing thread. > - * @param entry The start entry information for @a executing. > - * @param lock_context The lock context. > - */ > -RTEMS_NO_RETURN void _Thread_Restart_self( > - Thread_Control *executing, > - const Thread_Entry_information *entry, > - ISR_lock_Context *lock_context > -); > - > /** > * @brief Restarts the thread. > * > @@ -296,7 +283,7 @@ RTEMS_NO_RETURN void _Thread_Restart_self( > * > * @retval STATUS_INCORRECT_STATE The thread was dormant. > */ > -Status_Control _Thread_Restart_other( > +Status_Control _Thread_Restart( >Thread_Control *the_thread, >const Thread_Entry_information *entry, >ISR_lock_Context *lock_context > diff --git a/cpukit/rtems/src/taskrestart.c b/cpukit/rtems/src/taskrestart.c > index 00b0635cef..6bf7358384 100644 > --- a/cpukit/rtems/src/taskrestart.c > +++ b/cpukit/rtems/src/taskrestart.c > @@ -48,13 +48,7 @@ rtems_status_code rtems_task_restart( > >entry = the_thread->Start.Entry; >entry.Kinds.Numeric.argument = argument; > - > - if ( the_thread == _Thread_Executing ) { > -_Thread_Restart_self( the_thread, , _context ); > -RTEMS_UNREACHABLE(); > - } > - > - status = _Thread_Restart_other( the_thread, , _context ); > + status = _Thread_Restart( the_thread, , _context ); > >return _Status_Get( status ); > } > diff --git a/cpukit/score/src/threadrestart.c > b/cpukit/score/src/threadrestart.c > index d99c14afc0..7b8c481b80 100644 > --- a/cpukit/score/src/threadrestart.c > +++ b/cpukit/score/src/threadrestart.c > @@ -5,8 +5,7 @@ > * > * @brief This source file contains the implementation of _Thread_Cancel(), > * _Thread_Change_life(), _Thread_Close(), _Thread_Exit(), _Thread_Join(), > - * _Thread_Kill_zombies(), _Thread_Restart_other(), _Thread_Restart_self(), > - * and _Thread_Set_life_protection(). > + * _Thread_Kill_zombies(), _Thread_Restart(), and > _Thread_Set_life_protection(). > */ > > /* > @@ -517,7 +516,7 @@ void _Thread_Exit( >_Thread_State_release( executing, _context ); > } > > -Status_Control _Thread_Restart_other( > +Status_Control _Thread_Restart( >Thread_Control *the_thread, >const Thread_Entry_information *entry, >ISR_lock_Context *lock_context > @@ -525,6 +524,7 @@ Status_Control _Thread_Restart_other( > { >Thread_Life_stateprevious; >Per_CPU_Control *cpu_self; > + Thread_Life_stateignore; >Thread_queue_Context queue_context; > >_Thread_State_acquire_critical( the_thread, lock_context ); > @@ -534,16 +534,25 @@ Status_Control _Thread_Restart_other( > return STATUS_INCORRECT_STATE; >} > > + cpu_self = _Thread_Dispatch_disable_critical( lock_context ); > + > + if ( > +the_thread == _Per_CPU_Get_executing( cpu_self ) && > +!_ISR_Is_in_progress() > + ) { > +ignore = THREAD_LIFE_PROTECTED | THREAD_LIFE_CHANGE_DEFERRED; > + } else { > +ignore = 0; > + } > + >the_thread->Start.Entry = *entry; >previous = _Thread_Change_life_locked( > the_thread, > 0, > THREAD_LIFE_RESTARTING, > -0 > +ignore >); > > - cpu_self = _Thread_Dispatch_disable_critical( lock_context ); > - >if ( _Thread_Is_life_change_allowed( previous ) ) { > _Thread_Add_life_change_request( the_thread ); > _Thread_State_release( the_thread, lock_context ); > @@ -573,53 +582,6 @@ Status_Control _Thread_Restart_other( >
RE: [PATCH v3 1/5] libcsupport: Added futimens() and utimensat()
Reply is below. -Original Message- From: Gedare Bloom Sent: Wednesday, May 12, 2021 12:34 PM To: Ryan Long Cc: devel@rtems.org Subject: Re: [PATCH v3 1/5] libcsupport: Added futimens() and utimensat() On Wed, May 12, 2021 at 7:33 AM Ryan Long wrote: > > Created futimens.c and utimensat.c to add support for the POSIX > methods futimens() and utimensat(). > > utime() and utimes() are considered obsolote by POSIX, but RTEMS will > continue to support them. > > Closes #4396 > --- > cpukit/Makefile.am | 2 + > cpukit/include/rtems/libio_.h| 64 - > cpukit/include/rtems/score/timespec.h| 16 ++- > cpukit/libcsupport/src/futimens.c| 87 > cpukit/libcsupport/src/utimensat.c | 224 > +++ > cpukit/score/src/timespecisnonnegative.c | 35 + > spec/build/cpukit/librtemscpu.yml| 3 + > 7 files changed, 426 insertions(+), 5 deletions(-) create mode > 100644 cpukit/libcsupport/src/futimens.c create mode 100644 > cpukit/libcsupport/src/utimensat.c > create mode 100644 cpukit/score/src/timespecisnonnegative.c > > diff --git a/cpukit/Makefile.am b/cpukit/Makefile.am index > b0df610..29b4207 100644 > --- a/cpukit/Makefile.am > +++ b/cpukit/Makefile.am > @@ -262,6 +262,8 @@ librtemscpu_a_SOURCES += libcsupport/src/unmount.c > librtemscpu_a_SOURCES += libcsupport/src/__usrenv.c > librtemscpu_a_SOURCES += libcsupport/src/utime.c > librtemscpu_a_SOURCES += libcsupport/src/utimes.c > +librtemscpu_a_SOURCES += libcsupport/src/futimens.c > +librtemscpu_a_SOURCES += libcsupport/src/utimensat.c > librtemscpu_a_SOURCES += libcsupport/src/utsname.c > librtemscpu_a_SOURCES += libcsupport/src/vprintk.c > librtemscpu_a_SOURCES += libcsupport/src/write.c diff --git > a/cpukit/include/rtems/libio_.h b/cpukit/include/rtems/libio_.h index > e9eb462..b7455ef 100644 > --- a/cpukit/include/rtems/libio_.h > +++ b/cpukit/include/rtems/libio_.h > @@ -2,13 +2,12 @@ > * @file > * > * @brief LibIO Internal Interface > - * > + * > * This file is the libio internal interface. > */ > > /* > - * COPYRIGHT (c) 1989-2011. > - * On-Line Applications Research Corporation (OAR). > + * COPYRIGHT (C) 1989, 2021 On-Line Applications Research Corporation (OAR). > * > * Modifications to support reference counting in the file system are > * Copyright (c) 2012 embedded brains GmbH. > @@ -30,6 +29,7 @@ > #include > #include > #include > +#include > > #ifdef __cplusplus > extern "C" { > @@ -357,6 +357,64 @@ static inline void rtems_filesystem_instance_unlock( >(*mt_entry->ops->unlock_h)( mt_entry ); } > > +/** > + * @brief Checks the tv_nsec member of a timespec struct > + * > + * This function is used with utimensat() and futimens() only. This > +ensures > + * that the value in the tv_nsec member is equal to either UTIME_NOW, > + * UTIME_OMIT, or a value greater-than or equal to zero and less than > +a > + * billion. > + * > + * @param[in] time The timespec struct to be validated > + * > + * @retval Returns true if tv_nsec member is a valid value, otherwise false. > + */ > +bool rtems_filesystem_utime_tv_nsec_valid( struct timespec time ); > + > +/** > + * @brief Determines if the process has write permissions to a file I think it is more specific than that. Also, missing period. > + * > + * The timespec at index 0 is the access time, the timespec at index > + 1 is the > + * modification time. Should this note be on the @param[in] times below? [Ryan Long] Makes sense. I'll move it there. > + * > + * This function is only used with utimensat() and futimens(). This > + checks > + * whether the process has write access to a file, and checks for > + EACCES > + * and EPERM errors depending on what values are in @times and if the > + process > + * has write permissions to the file. > + * > + * @param[in] currentloc The current location to a file > + * @param[in] times The timespec instance that will update the > + timestamps update? nothing about this function seems to be an update? [Ryan Long] I'll change this to just say something like "The timespec instance used to check for errors". Is there another name for this function that you think would fit better? While it is checking for the appropriate permissions, it's also checking for errors, so I'm not sure if this function name fits anymore. > + * > + * @retval Returns 0 if the process has write permissions, otherwise -1. > + */ > +int rtems_filesystem_utime_check_permissions( > + const rtems_filesystem_location_info_t *currentloc, > + const struct timespec times[2] > +); > + > +/** > + * @brief Checks @times and fills @new_times with the time to be > +written > + * > + * For each of the arguments, the timespec at index 0 is the access > +time, and > + * the timespec at index 1 is the modification time. > + * > + * This function is only used with utimensat() and futimens(). @times > +contains > + * the constant
Re: Inconsistent behaviour with respect to the ticks in the *_when() directives
On Fri, May 14, 2021 at 12:26 AM Sebastian Huber wrote: > > Hello, > > I noticed that we have an inconsistent behaviour with respect to the > handling of the ticks member in the *_when() directives. In all *_when() > directives the ticks member is not used to calculate the watchdog > expiration time, see also: > > https://lists.rtems.org/pipermail/users/2020-December/068006.html > > However, the rtems_task_wake_when() directive ignores the ticks member > of the time of day completely, unlike the rtems_timer_fire_when() and > rtems_timer_server_fire_when() directives which check that the ticks are > valid and then ignore them. > > We should use a common way to deal with the ticks member. If we ignore > the value, then this would make it more difficult to support it in the > future. The watchdog implementation supports a nanoseconds resolution. > If we check the ticks in rtems_task_wake_when() existing applications > may get an error status after the change. > I'm in favor of making the behavior consistent and future-looking. Let's validate the ticks parameter but not use it. Recommend that users set it to 0? That allows a future modification to use it with fewer surprises. > -- > embedded brains GmbH > Herr Sebastian HUBER > Dornierstr. 4 > 82178 Puchheim > Germany > email: sebastian.hu...@embedded-brains.de > phone: +49-89-18 94 741 - 16 > fax: +49-89-18 94 741 - 08 > > Registergericht: Amtsgericht München > Registernummer: HRB 157899 > Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler > Unsere Datenschutzerklärung finden Sie hier: > https://embedded-brains.de/datenschutzerklaerung/ > ___ > devel mailing list > devel@rtems.org > http://lists.rtems.org/mailman/listinfo/devel ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel
[PATCH 1/2] rtems: Always set the real priority during restart
Unconditionally set the real priority of the task to its initial priority during a task restart. Close #4411. --- cpukit/score/src/threadrestart.c | 58 ++-- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/cpukit/score/src/threadrestart.c b/cpukit/score/src/threadrestart.c index dcbf11c713..d99c14afc0 100644 --- a/cpukit/score/src/threadrestart.c +++ b/cpukit/score/src/threadrestart.c @@ -375,17 +375,6 @@ static void _Thread_Remove_life_change_request( Thread_Control *the_thread ) _Thread_State_release( the_thread, _context ); } -static void _Thread_Finalize_life_change( - Thread_Control *the_thread, - Priority_Control priority -) -{ - _Thread_queue_Extract_with_proxy( the_thread ); - _Thread_Timer_remove( the_thread ); - _Thread_Raise_real_priority( the_thread, priority ); - _Thread_Remove_life_change_request( the_thread ); -} - void _Thread_Join( Thread_Control *the_thread, States_Controlwaiting_for_join, @@ -424,7 +413,6 @@ void _Thread_Cancel( ISR_lock_Context lock_context; Thread_Life_state previous; Per_CPU_Control *cpu_self; - Priority_Control priority; _Assert( the_thread != executing ); @@ -439,21 +427,26 @@ void _Thread_Cancel( ); cpu_self = _Thread_Dispatch_disable_critical( _context ); - priority = _Thread_Get_priority( executing ); if ( _States_Is_dormant( the_thread->current_state ) ) { _Thread_State_release( the_thread, _context ); _Thread_Make_zombie( the_thread ); - } else if ( _Thread_Is_life_change_allowed( previous ) ) { -_Thread_Add_life_change_request( the_thread ); -_Thread_State_release( the_thread, _context ); - -_Thread_Finalize_life_change( the_thread, priority ); } else { +Priority_Control priority; + _Thread_Add_life_change_request( the_thread ); -_Thread_Clear_state_locked( the_thread, STATES_SUSPENDED ); -_Thread_State_release( the_thread, _context ); +if ( _Thread_Is_life_change_allowed( previous ) ) { + _Thread_State_release( the_thread, _context ); + + _Thread_queue_Extract_with_proxy( the_thread ); + _Thread_Timer_remove( the_thread ); +} else { + _Thread_Clear_state_locked( the_thread, STATES_SUSPENDED ); + _Thread_State_release( the_thread, _context ); +} + +priority = _Thread_Get_priority( executing ); _Thread_Raise_real_priority( the_thread, priority ); _Thread_Remove_life_change_request( the_thread ); } @@ -530,8 +523,9 @@ Status_Control _Thread_Restart_other( ISR_lock_Context *lock_context ) { - Thread_Life_state previous; - Per_CPU_Control *cpu_self; + Thread_Life_stateprevious; + Per_CPU_Control *cpu_self; + Thread_queue_Context queue_context; _Thread_State_acquire_critical( the_thread, lock_context ); @@ -554,15 +548,27 @@ Status_Control _Thread_Restart_other( _Thread_Add_life_change_request( the_thread ); _Thread_State_release( the_thread, lock_context ); -_Thread_Finalize_life_change( - the_thread, - the_thread->Start.initial_priority -); +_Thread_queue_Extract_with_proxy( the_thread ); +_Thread_Timer_remove( the_thread ); +_Thread_Remove_life_change_request( the_thread ); } else { _Thread_Clear_state_locked( the_thread, STATES_SUSPENDED ); _Thread_State_release( the_thread, lock_context ); } + _Thread_queue_Context_initialize( _context ); + _Thread_queue_Context_clear_priority_updates( _context ); + _Thread_Wait_acquire( the_thread, _context ); + _Thread_Priority_change( +the_thread, +_thread->Real_priority, +the_thread->Start.initial_priority, +false, +_context + ); + _Thread_Wait_release( the_thread, _context ); + + _Thread_Priority_update( _context ); _Thread_Dispatch_enable( cpu_self ); return STATUS_SUCCESSFUL; } -- 2.26.2 ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel
[PATCH 2/2] rtems: Fix task restart within interrupt context
rtems_task_restart() may be called from within interrupt context. So checking only that the thread to restart is equal to the executing thread is insufficient to determine a self restart. We have to also check that no ISR is in progress. Merge _Thread_Restart_other() and _Thread_Restart_self() into one _Thread_Restart() since they share a lot of common code. Close #4412. --- cpukit/include/rtems/score/threadimpl.h | 15 +- cpukit/rtems/src/taskrestart.c | 8 +-- cpukit/score/src/threadrestart.c| 68 ++--- 3 files changed, 17 insertions(+), 74 deletions(-) diff --git a/cpukit/include/rtems/score/threadimpl.h b/cpukit/include/rtems/score/threadimpl.h index 8674a3f2b3..44785cd937 100644 --- a/cpukit/include/rtems/score/threadimpl.h +++ b/cpukit/include/rtems/score/threadimpl.h @@ -270,19 +270,6 @@ Status_Control _Thread_Start( ISR_lock_Context *lock_context ); -/** - * @brief Restarts the currently executing thread. - * - * @param[in, out] executing The currently executing thread. - * @param entry The start entry information for @a executing. - * @param lock_context The lock context. - */ -RTEMS_NO_RETURN void _Thread_Restart_self( - Thread_Control *executing, - const Thread_Entry_information *entry, - ISR_lock_Context *lock_context -); - /** * @brief Restarts the thread. * @@ -296,7 +283,7 @@ RTEMS_NO_RETURN void _Thread_Restart_self( * * @retval STATUS_INCORRECT_STATE The thread was dormant. */ -Status_Control _Thread_Restart_other( +Status_Control _Thread_Restart( Thread_Control *the_thread, const Thread_Entry_information *entry, ISR_lock_Context *lock_context diff --git a/cpukit/rtems/src/taskrestart.c b/cpukit/rtems/src/taskrestart.c index 00b0635cef..6bf7358384 100644 --- a/cpukit/rtems/src/taskrestart.c +++ b/cpukit/rtems/src/taskrestart.c @@ -48,13 +48,7 @@ rtems_status_code rtems_task_restart( entry = the_thread->Start.Entry; entry.Kinds.Numeric.argument = argument; - - if ( the_thread == _Thread_Executing ) { -_Thread_Restart_self( the_thread, , _context ); -RTEMS_UNREACHABLE(); - } - - status = _Thread_Restart_other( the_thread, , _context ); + status = _Thread_Restart( the_thread, , _context ); return _Status_Get( status ); } diff --git a/cpukit/score/src/threadrestart.c b/cpukit/score/src/threadrestart.c index d99c14afc0..7b8c481b80 100644 --- a/cpukit/score/src/threadrestart.c +++ b/cpukit/score/src/threadrestart.c @@ -5,8 +5,7 @@ * * @brief This source file contains the implementation of _Thread_Cancel(), * _Thread_Change_life(), _Thread_Close(), _Thread_Exit(), _Thread_Join(), - * _Thread_Kill_zombies(), _Thread_Restart_other(), _Thread_Restart_self(), - * and _Thread_Set_life_protection(). + * _Thread_Kill_zombies(), _Thread_Restart(), and _Thread_Set_life_protection(). */ /* @@ -517,7 +516,7 @@ void _Thread_Exit( _Thread_State_release( executing, _context ); } -Status_Control _Thread_Restart_other( +Status_Control _Thread_Restart( Thread_Control *the_thread, const Thread_Entry_information *entry, ISR_lock_Context *lock_context @@ -525,6 +524,7 @@ Status_Control _Thread_Restart_other( { Thread_Life_stateprevious; Per_CPU_Control *cpu_self; + Thread_Life_stateignore; Thread_queue_Context queue_context; _Thread_State_acquire_critical( the_thread, lock_context ); @@ -534,16 +534,25 @@ Status_Control _Thread_Restart_other( return STATUS_INCORRECT_STATE; } + cpu_self = _Thread_Dispatch_disable_critical( lock_context ); + + if ( +the_thread == _Per_CPU_Get_executing( cpu_self ) && +!_ISR_Is_in_progress() + ) { +ignore = THREAD_LIFE_PROTECTED | THREAD_LIFE_CHANGE_DEFERRED; + } else { +ignore = 0; + } + the_thread->Start.Entry = *entry; previous = _Thread_Change_life_locked( the_thread, 0, THREAD_LIFE_RESTARTING, -0 +ignore ); - cpu_self = _Thread_Dispatch_disable_critical( lock_context ); - if ( _Thread_Is_life_change_allowed( previous ) ) { _Thread_Add_life_change_request( the_thread ); _Thread_State_release( the_thread, lock_context ); @@ -573,53 +582,6 @@ Status_Control _Thread_Restart_other( return STATUS_SUCCESSFUL; } -void _Thread_Restart_self( - Thread_Control *executing, - const Thread_Entry_information *entry, - ISR_lock_Context *lock_context -) -{ - Per_CPU_Control *cpu_self; - Thread_queue_Context queue_context; - - _Assert( -_Watchdog_Get_state( >Timer.Watchdog ) == WATCHDOG_INACTIVE - ); - _Assert( -executing->current_state == STATES_READY - || executing->current_state == STATES_SUSPENDED - ); - - _Thread_queue_Context_initialize( _context ); - _Thread_queue_Context_clear_priority_updates( _context ); - _Thread_State_acquire_critical( executing, lock_context ); - -
[PATCH 0/2] Fix two rtems_task_restart() issues
Sebastian Huber (2): rtems: Always set the real priority during restart rtems: Fix task restart within interrupt context cpukit/include/rtems/score/threadimpl.h | 15 +--- cpukit/rtems/src/taskrestart.c | 8 +- cpukit/score/src/threadrestart.c| 114 +--- 3 files changed, 43 insertions(+), 94 deletions(-) -- 2.26.2 ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel
Inconsistent behaviour with respect to the ticks in the *_when() directives
Hello, I noticed that we have an inconsistent behaviour with respect to the handling of the ticks member in the *_when() directives. In all *_when() directives the ticks member is not used to calculate the watchdog expiration time, see also: https://lists.rtems.org/pipermail/users/2020-December/068006.html However, the rtems_task_wake_when() directive ignores the ticks member of the time of day completely, unlike the rtems_timer_fire_when() and rtems_timer_server_fire_when() directives which check that the ticks are valid and then ignore them. We should use a common way to deal with the ticks member. If we ignore the value, then this would make it more difficult to support it in the future. The watchdog implementation supports a nanoseconds resolution. If we check the ticks in rtems_task_wake_when() existing applications may get an error status after the change. -- embedded brains GmbH Herr Sebastian HUBER Dornierstr. 4 82178 Puchheim Germany email: sebastian.hu...@embedded-brains.de phone: +49-89-18 94 741 - 16 fax: +49-89-18 94 741 - 08 Registergericht: Amtsgericht München Registernummer: HRB 157899 Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler Unsere Datenschutzerklärung finden Sie hier: https://embedded-brains.de/datenschutzerklaerung/ ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel