Browse Source

[kconfig] add 64bit default value for stack size. set tick HZ as 1000 by default (#5778)

* [kconfig] add 64bit default value for stack size. set tick HZ as 1000 by default

* 用RT_KSERVICE_USING_STDLIB_MEMXXX代替RT_KSERVICE_USING_STDLIB_MEMCP/MEMSET
将RT_KSERVICE_USING_STDLIB设置为默认开启

* 优化rt_kprintf支持longlong的能力,默认在64位CPU为开启状态
RT_PRINTF_LONGLONG命名不规范,更改为RT_KPRINTF_USING_LONGLONG

* fix commit error

* fix error

* 优化 system 函数

* RT_KSERVICE_USING_STDLIB_MEMXXX->RT_KSERVICE_USING_STDLIB_MEMORY
Man, Jianting (Meco) 3 years ago
parent
commit
03823b5016
5 changed files with 56 additions and 60 deletions
  1. 2 0
      components/Kconfig
  2. 4 8
      components/libc/compilers/common/stdlib.c
  3. 8 12
      include/rtthread.h
  4. 23 18
      src/Kconfig
  5. 19 22
      src/kservice.c

+ 2 - 0
components/Kconfig

@@ -11,7 +11,9 @@ config RT_USING_USER_MAIN
     if RT_USING_USER_MAIN
     if RT_USING_USER_MAIN
         config RT_MAIN_THREAD_STACK_SIZE
         config RT_MAIN_THREAD_STACK_SIZE
             int "Set main thread stack size"
             int "Set main thread stack size"
+            default 6144 if ARCH_CPU_64BIT
             default 2048
             default 2048
+
         config RT_MAIN_THREAD_PRIORITY
         config RT_MAIN_THREAD_PRIORITY
             int "Set main thread priority" 
             int "Set main thread priority" 
             default 4  if RT_THREAD_PRIORITY_8
             default 4  if RT_THREAD_PRIORITY_8

+ 4 - 8
components/libc/compilers/common/stdlib.c

@@ -30,16 +30,12 @@ int system(const char *command)
 {
 {
     extern int msh_exec(char *cmd, rt_size_t length);
     extern int msh_exec(char *cmd, rt_size_t length);
 
 
-    int ret = -RT_ENOMEM;
-    char *cmd = rt_strdup(command);
-
-    if (cmd)
+    if (command)
     {
     {
-        ret = msh_exec(cmd, rt_strlen(cmd));
-        rt_free(cmd);
+        msh_exec((char *)command, rt_strlen(command));
     }
     }
 
 
-    return ret;
+    return 0;
 }
 }
 RTM_EXPORT(system);
 RTM_EXPORT(system);
-#endif
+#endif /* RT_USING_MSH */

+ 8 - 12
include/rtthread.h

@@ -599,17 +599,14 @@ int *_rt_errno(void);
 
 
 int __rt_ffs(int value);
 int __rt_ffs(int value);
 
 
-#ifndef RT_KSERVICE_USING_STDLIB_MEMSET
+#ifndef RT_KSERVICE_USING_STDLIB_MEMORY
 void *rt_memset(void *src, int c, rt_ubase_t n);
 void *rt_memset(void *src, int c, rt_ubase_t n);
-#endif /* RT_KSERVICE_USING_STDLIB_MEMSET */
-#ifndef RT_KSERVICE_USING_STDLIB_MEMCPY
 void *rt_memcpy(void *dest, const void *src, rt_ubase_t n);
 void *rt_memcpy(void *dest, const void *src, rt_ubase_t n);
-#endif /* RT_KSERVICE_USING_STDLIB_MEMCPY */
-char *rt_strdup(const char *s);
-
-#ifndef RT_KSERVICE_USING_STDLIB
 void *rt_memmove(void *dest, const void *src, rt_size_t n);
 void *rt_memmove(void *dest, const void *src, rt_size_t n);
 rt_int32_t rt_memcmp(const void *cs, const void *ct, rt_size_t count);
 rt_int32_t rt_memcmp(const void *cs, const void *ct, rt_size_t count);
+#endif /* RT_KSERVICE_USING_STDLIB_MEMORY */
+
+#ifndef RT_KSERVICE_USING_STDLIB
 char *rt_strstr(const char *str1, const char *str2);
 char *rt_strstr(const char *str1, const char *str2);
 rt_int32_t rt_strcasecmp(const char *a, const char *b);
 rt_int32_t rt_strcasecmp(const char *a, const char *b);
 char *rt_strcpy(char *dst, const char *src);
 char *rt_strcpy(char *dst, const char *src);
@@ -619,14 +616,12 @@ rt_int32_t rt_strcmp(const char *cs, const char *ct);
 rt_size_t rt_strlen(const char *src);
 rt_size_t rt_strlen(const char *src);
 #else
 #else
 #include <string.h>
 #include <string.h>
-#ifdef RT_KSERVICE_USING_STDLIB_MEMSET
+#ifdef RT_KSERVICE_USING_STDLIB_MEMORY
 #define rt_memset(s, c, count)      memset(s, c, count)
 #define rt_memset(s, c, count)      memset(s, c, count)
-#endif /* RT_KSERVICE_USING_STDLIB_MEMSET */
-#ifdef RT_KSERVICE_USING_STDLIB_MEMCPY
 #define rt_memcpy(dst, src, count)  memcpy(dst, src, count)
 #define rt_memcpy(dst, src, count)  memcpy(dst, src, count)
-#endif /* RT_KSERVICE_USING_STDLIB_MEMCPY */
 #define rt_memmove(dest, src, n)    memmove(dest, src, n)
 #define rt_memmove(dest, src, n)    memmove(dest, src, n)
 #define rt_memcmp(cs, ct, count)    memcmp(cs, ct, count)
 #define rt_memcmp(cs, ct, count)    memcmp(cs, ct, count)
+#endif /* RT_KSERVICE_USING_STDLIB_MEMORY */
 #define rt_strstr(str1, str2)       strstr(str1, str2)
 #define rt_strstr(str1, str2)       strstr(str1, str2)
 #define rt_strcasecmp(a, b)         strcasecmp(a, b)
 #define rt_strcasecmp(a, b)         strcasecmp(a, b)
 #define rt_strcpy(dest, src)        strcpy(dest, src)
 #define rt_strcpy(dest, src)        strcpy(dest, src)
@@ -636,6 +631,8 @@ rt_size_t rt_strlen(const char *src);
 #define rt_strlen(src)              strlen(src)
 #define rt_strlen(src)              strlen(src)
 #endif /*RT_KSERVICE_USING_STDLIB*/
 #endif /*RT_KSERVICE_USING_STDLIB*/
 
 
+char *rt_strdup(const char *s);
+
 #if !defined(RT_KSERVICE_USING_STDLIB) || defined(__ARMCC_VERSION)
 #if !defined(RT_KSERVICE_USING_STDLIB) || defined(__ARMCC_VERSION)
 rt_size_t rt_strnlen(const char *s, rt_ubase_t maxlen);
 rt_size_t rt_strnlen(const char *s, rt_ubase_t maxlen);
 #else
 #else
@@ -644,7 +641,6 @@ rt_size_t rt_strnlen(const char *s, rt_ubase_t maxlen);
 
 
 #ifdef __ARMCC_VERSION
 #ifdef __ARMCC_VERSION
 /* MDK doesn't have these APIs */
 /* MDK doesn't have these APIs */
-char* strdup(const char* str);
 rt_size_t strnlen(const char *s, rt_size_t maxlen);
 rt_size_t strnlen(const char *s, rt_size_t maxlen);
 #endif /* __ARMCC_VERSION */
 #endif /* __ARMCC_VERSION */
 
 

+ 23 - 18
src/Kconfig

@@ -62,7 +62,7 @@ config RT_THREAD_PRIORITY_MAX
 config RT_TICK_PER_SECOND
 config RT_TICK_PER_SECOND
     int "Tick frequency, Hz"
     int "Tick frequency, Hz"
     range 10 1000
     range 10 1000
-    default 100
+    default 1000
     help
     help
         System's tick frequency, Hz.
         System's tick frequency, Hz.
 
 
@@ -80,10 +80,11 @@ config RT_USING_HOOK
     help
     help
         Enable the hook function when system running, such as idle thread hook,
         Enable the hook function when system running, such as idle thread hook,
         thread context switch etc.
         thread context switch etc.
+
     if RT_USING_HOOK
     if RT_USING_HOOK
         config RT_HOOK_USING_FUNC_PTR
         config RT_HOOK_USING_FUNC_PTR
-        bool "Using function pointers as system hook"
-        default y
+            bool "Using function pointers as system hook"
+            default y
     endif
     endif
 
 
 config RT_USING_IDLE_HOOK
 config RT_USING_IDLE_HOOK
@@ -91,16 +92,17 @@ config RT_USING_IDLE_HOOK
     default y if RT_USING_HOOK
     default y if RT_USING_HOOK
 
 
     if RT_USING_IDLE_HOOK
     if RT_USING_IDLE_HOOK
-    config RT_IDLE_HOOK_LIST_SIZE
-        int "The max size of idle hook list"
-        default 4
-        range 1 16
-        help
-            The system has a hook list. This is the hook list size.
+        config RT_IDLE_HOOK_LIST_SIZE
+            int "The max size of idle hook list"
+            default 4
+            range 1 16
+            help
+                The system has a hook list. This is the hook list size.
     endif
     endif
 
 
 config IDLE_THREAD_STACK_SIZE
 config IDLE_THREAD_STACK_SIZE
     int "The stack size of idle thread"
     int "The stack size of idle thread"
+    default 1024 if ARCH_CPU_64BIT
     default 256
     default 256
 
 
 config SYSTEM_THREAD_STACK_SIZE
 config SYSTEM_THREAD_STACK_SIZE
@@ -122,6 +124,7 @@ if RT_USING_TIMER_SOFT
 
 
     config RT_TIMER_THREAD_STACK_SIZE
     config RT_TIMER_THREAD_STACK_SIZE
         int "The stack size of timer thread"
         int "The stack size of timer thread"
+        default 2048 if ARCH_CPU_64BIT
         default 512
         default 512
 endif
 endif
 
 
@@ -129,16 +132,14 @@ menu "kservice optimization"
 
 
     config RT_KSERVICE_USING_STDLIB
     config RT_KSERVICE_USING_STDLIB
         bool "Enable kservice to use standard C library"
         bool "Enable kservice to use standard C library"
-        default n
+        default y
 
 
     if RT_KSERVICE_USING_STDLIB
     if RT_KSERVICE_USING_STDLIB
-        config RT_KSERVICE_USING_STDLIB_MEMCPY
-            bool "Use memcpy to replace rt_memcpy (faster, but not safe)"
-            default n
-
-        config RT_KSERVICE_USING_STDLIB_MEMSET
-            bool "Use memset to replace rt_memset (faster, but not safe)"
+        config RT_KSERVICE_USING_STDLIB_MEMORY
+            bool "Use stdlib memory functions to replace (faster, but not safe)"
             default n
             default n
+            help
+                e.g. use memcpy to replace rt_memcpy
     endif
     endif
 
 
     config RT_KSERVICE_USING_TINY_SIZE
     config RT_KSERVICE_USING_TINY_SIZE
@@ -149,9 +150,13 @@ menu "kservice optimization"
         bool "Enable kservice to use tiny finding first bit set method"
         bool "Enable kservice to use tiny finding first bit set method"
         default n
         default n
 
 
-    config RT_PRINTF_LONGLONG
-        bool "Enable rt_printf-family functions to support long long format"
+    config RT_KPRINTF_USING_LONGLONG
+        bool "Enable rt_printf-family functions to support long-long format"
+        default y if ARCH_CPU_64BIT
         default n
         default n
+        help
+            Enable rt_printf()/rt_snprintf()/rt_sprintf()/rt_vsnprintf()/rt_vsprintf()
+            functions to support long-long format
 
 
 endmenu
 endmenu
 
 

+ 19 - 22
src/kservice.c

@@ -117,7 +117,7 @@ int *_rt_errno(void)
 }
 }
 RTM_EXPORT(_rt_errno);
 RTM_EXPORT(_rt_errno);
 
 
-#ifndef RT_KSERVICE_USING_STDLIB_MEMSET
+#ifndef RT_KSERVICE_USING_STDLIB_MEMORY
 /**
 /**
  * This function will set the content of memory to specified value.
  * This function will set the content of memory to specified value.
  *
  *
@@ -203,9 +203,7 @@ RT_WEAK void *rt_memset(void *s, int c, rt_ubase_t count)
 #endif /* RT_KSERVICE_USING_TINY_SIZE */
 #endif /* RT_KSERVICE_USING_TINY_SIZE */
 }
 }
 RTM_EXPORT(rt_memset);
 RTM_EXPORT(rt_memset);
-#endif /* RT_KSERVICE_USING_STDLIB_MEMSET */
 
 
-#ifndef RT_KSERVICE_USING_STDLIB_MEMCPY
 /**
 /**
  * This function will copy memory content from source address to destination address.
  * This function will copy memory content from source address to destination address.
  *
  *
@@ -289,9 +287,6 @@ RT_WEAK void *rt_memcpy(void *dst, const void *src, rt_ubase_t count)
 #endif /* RT_KSERVICE_USING_TINY_SIZE */
 #endif /* RT_KSERVICE_USING_TINY_SIZE */
 }
 }
 RTM_EXPORT(rt_memcpy);
 RTM_EXPORT(rt_memcpy);
-#endif /* RT_KSERVICE_USING_STDLIB_MEMCPY */
-
-#ifndef RT_KSERVICE_USING_STDLIB
 
 
 /**
 /**
  * This function will move memory content from source address to destination
  * This function will move memory content from source address to destination
@@ -354,7 +349,9 @@ rt_int32_t rt_memcmp(const void *cs, const void *ct, rt_size_t count)
     return res;
     return res;
 }
 }
 RTM_EXPORT(rt_memcmp);
 RTM_EXPORT(rt_memcmp);
+#endif /* RT_KSERVICE_USING_STDLIB_MEMORY*/
 
 
+#ifndef RT_KSERVICE_USING_STDLIB
 /**
 /**
  * This function will return the first occurrence of a string, without the
  * This function will return the first occurrence of a string, without the
  * terminator '\0'.
  * terminator '\0'.
@@ -629,18 +626,18 @@ RTM_EXPORT(rt_show_version);
  *
  *
  * @return the duplicated string pointer.
  * @return the duplicated string pointer.
  */
  */
-#ifdef RT_PRINTF_LONGLONG
+#ifdef RT_KPRINTF_USING_LONGLONG
 rt_inline int divide(long long *n, int base)
 rt_inline int divide(long long *n, int base)
 #else
 #else
 rt_inline int divide(long *n, int base)
 rt_inline int divide(long *n, int base)
-#endif /* RT_PRINTF_LONGLONG */
+#endif /* RT_KPRINTF_USING_LONGLONG */
 {
 {
     int res;
     int res;
 
 
     /* optimized for processor which does not support divide instructions. */
     /* optimized for processor which does not support divide instructions. */
     if (base == 10)
     if (base == 10)
     {
     {
-#ifdef RT_PRINTF_LONGLONG
+#ifdef RT_KPRINTF_USING_LONGLONG
         res = (int)(((unsigned long long)*n) % 10U);
         res = (int)(((unsigned long long)*n) % 10U);
         *n = (long long)(((unsigned long long)*n) / 10U);
         *n = (long long)(((unsigned long long)*n) / 10U);
 #else
 #else
@@ -650,7 +647,7 @@ rt_inline int divide(long *n, int base)
     }
     }
     else
     else
     {
     {
-#ifdef RT_PRINTF_LONGLONG
+#ifdef RT_KPRINTF_USING_LONGLONG
         res = (int)(((unsigned long long)*n) % 16U);
         res = (int)(((unsigned long long)*n) % 16U);
         *n = (long long)(((unsigned long long)*n) / 16U);
         *n = (long long)(((unsigned long long)*n) / 16U);
 #else
 #else
@@ -681,11 +678,11 @@ rt_inline int skip_atoi(const char **s)
 
 
 static char *print_number(char *buf,
 static char *print_number(char *buf,
                           char *end,
                           char *end,
-#ifdef RT_PRINTF_LONGLONG
+#ifdef RT_KPRINTF_USING_LONGLONG
                           long long  num,
                           long long  num,
 #else
 #else
                           long  num,
                           long  num,
-#endif /* RT_PRINTF_LONGLONG */
+#endif /* RT_KPRINTF_USING_LONGLONG */
                           int   base,
                           int   base,
                           int   s,
                           int   s,
 #ifdef RT_PRINTF_PRECISION
 #ifdef RT_PRINTF_PRECISION
@@ -694,11 +691,11 @@ static char *print_number(char *buf,
                           int   type)
                           int   type)
 {
 {
     char c, sign;
     char c, sign;
-#ifdef RT_PRINTF_LONGLONG
+#ifdef RT_KPRINTF_USING_LONGLONG
     char tmp[32];
     char tmp[32];
 #else
 #else
     char tmp[16];
     char tmp[16];
-#endif /* RT_PRINTF_LONGLONG */
+#endif /* RT_KPRINTF_USING_LONGLONG */
     int precision_bak = precision;
     int precision_bak = precision;
     const char *digits;
     const char *digits;
     static const char small_digits[] = "0123456789abcdef";
     static const char small_digits[] = "0123456789abcdef";
@@ -855,11 +852,11 @@ static char *print_number(char *buf,
  */
  */
 RT_WEAK int rt_vsnprintf(char *buf, rt_size_t size, const char *fmt, va_list args)
 RT_WEAK int rt_vsnprintf(char *buf, rt_size_t size, const char *fmt, va_list args)
 {
 {
-#ifdef RT_PRINTF_LONGLONG
+#ifdef RT_KPRINTF_USING_LONGLONG
     unsigned long long num;
     unsigned long long num;
 #else
 #else
     rt_uint32_t num;
     rt_uint32_t num;
-#endif /* RT_PRINTF_LONGLONG */
+#endif /* RT_KPRINTF_USING_LONGLONG */
     int i, len;
     int i, len;
     char *str, *end, c;
     char *str, *end, c;
     const char *s;
     const char *s;
@@ -941,21 +938,21 @@ RT_WEAK int rt_vsnprintf(char *buf, rt_size_t size, const char *fmt, va_list arg
 #endif /* RT_PRINTF_PRECISION */
 #endif /* RT_PRINTF_PRECISION */
         /* get the conversion qualifier */
         /* get the conversion qualifier */
         qualifier = 0;
         qualifier = 0;
-#ifdef RT_PRINTF_LONGLONG
+#ifdef RT_KPRINTF_USING_LONGLONG
         if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L')
         if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L')
 #else
 #else
         if (*fmt == 'h' || *fmt == 'l')
         if (*fmt == 'h' || *fmt == 'l')
-#endif /* RT_PRINTF_LONGLONG */
+#endif /* RT_KPRINTF_USING_LONGLONG */
         {
         {
             qualifier = *fmt;
             qualifier = *fmt;
             ++ fmt;
             ++ fmt;
-#ifdef RT_PRINTF_LONGLONG
+#ifdef RT_KPRINTF_USING_LONGLONG
             if (qualifier == 'l' && *fmt == 'l')
             if (qualifier == 'l' && *fmt == 'l')
             {
             {
                 qualifier = 'L';
                 qualifier = 'L';
                 ++ fmt;
                 ++ fmt;
             }
             }
-#endif /* RT_PRINTF_LONGLONG */
+#endif /* RT_KPRINTF_USING_LONGLONG */
         }
         }
 
 
         /* the default base */
         /* the default base */
@@ -1073,12 +1070,12 @@ RT_WEAK int rt_vsnprintf(char *buf, rt_size_t size, const char *fmt, va_list arg
             continue;
             continue;
         }
         }
 
 
-#ifdef RT_PRINTF_LONGLONG
+#ifdef RT_KPRINTF_USING_LONGLONG
         if (qualifier == 'L') num = va_arg(args, long long);
         if (qualifier == 'L') num = va_arg(args, long long);
         else if (qualifier == 'l')
         else if (qualifier == 'l')
 #else
 #else
         if (qualifier == 'l')
         if (qualifier == 'l')
-#endif /* RT_PRINTF_LONGLONG */
+#endif /* RT_KPRINTF_USING_LONGLONG */
         {
         {
             num = va_arg(args, rt_uint32_t);
             num = va_arg(args, rt_uint32_t);
             if (flags & SIGN) num = (rt_int32_t)num;
             if (flags & SIGN) num = (rt_int32_t)num;