Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
keil_MDK
shell
相同优先级时间片轮转调度
时间片视频教程移植,时间片功能不起作用是什么情况
发布于 2020-07-23 20:47:48 浏览:1444
订阅该版
硬件:正点原子 战舰V3 采用HAL库编程 我的程序 链接:https://pan.baidu.com/s/11HBMzpyjGjtQ-kbWwAYJvg 提取码:t34w 移植RTOS(kernel及SHELL)至工程中,用MSH命令执行timeslice_sample程序,结果如下: ``` msh >timeslice_sample thread 1 is running ,thread 1 count = 0 thread 1 is running ,thread 1 count = 5 thread 1 is running ,thread 1 count = 10 thread 1 is running ,thread 1 count = 15 thread 1 is running ,thread 1 count = 20 thread 1 is running ,thread 1 count = 25 thread 1 is running ,thread 1 count = 30 thread 1 is running ,thread 1 count = 35 thread 1 is running ,thread 1 count = 40 thread 1 is running ,thread 1 count = 45 thread 1 is running ,thread 1 count = 50 thread 1 is running ,thread 1 count = 55 thread 1 is running ,thread 1 count = 60 thread 1 is running ,thread 1 count = 65 thread 1 is running ,thread 1 count = 70 thread 1 is running ,thread 1 count = 75 thread 1 is running ,thread 1 count = 80 thread 1 is running ,thread 1 count = 85 thread 1 is running ,thread 1 count = 90 thread 1 is running ,thread 1 count = 95 thread 1 is running ,thread 1 count = 100 thread 1 is running ,thread 1 count = 105 thread 1 is running ,thread 1 count = 110 thread 1 is running ,thread 1 count = 115 thread 1 is running ,thread 1 count = 120 thread 1 is running ,thread 1 count = 125 thread 1 is running ,thread 1 count = 130 thread 1 is running ,thread 1 count = 135 thread 1 is running ,thread 1 count = 140 thread 1 is running ,thread 1 count = 145 thread 1 is running ,thread 1 count = 150 thread 1 is running ,thread 1 count = 155 thread 1 is running ,thread 1 count = 160 thread 1 is running ,thread 1 count = 165 thread 1 is running ,thread 1 count = 170 thread 1 is running ,thread 1 count = 175 thread 1 is running ,thread 1 count = 180 thread 1 is running ,thread 1 count = 185 thread 1 is running ,thread 1 count = 190 thread 1 is running ,thread 1 count = 195 thread 1 is running ,thread 1 count = 200 thread 1 is running ,thread 1 count = 205 thread 2 is running ,thread 2 count = 0 thread 2 is running ,thread 2 count = 5 thread 2 is running ,thread 2 count = 10 thread 2 is running ,thread 2 count = 15 thread 2 is running ,thread 2 count = 20 thread 2 is running ,thread 2 count = 25 thread 2 is running ,thread 2 count = 30 thread 2 is running ,thread 2 count = 35 thread 2 is running ,thread 2 count = 40 thread 2 is running ,thread 2 count = 45 thread 2 is running ,thread 2 count = 50 thread 2 is running ,thread 2 count = 55 thread 2 is running ,thread 2 count = 60 thread 2 is running ,thread 2 count = 65 thread 2 is running ,thread 2 count = 70 thread 2 is running ,thread 2 count = 75 thread 2 is running ,thread 2 count = 80 thread 2 is running ,thread 2 count = 85 thread 2 is running ,thread 2 count = 90 thread 2 is running ,thread 2 count = 95 thread 2 is running ,thread 2 count = 100 thread 2 is running ,thread 2 count = 105 thread 2 is running ,thread 2 count = 110 thread 2 is running ,thread 2 count = 115 thread 2 is running ,thread 2 count = 120 thread 2 is running ,thread 2 count = 125 thread 2 is running ,thread 2 count = 130 thread 2 is running ,thread 2 count = 135 thread 2 is running ,thread 2 count = 140 thread 2 is running ,thread 2 count = 145 thread 2 is running ,thread 2 count = 150 thread 2 is running ,thread 2 count = 155 thread 2 is running ,thread 2 count = 160 thread 2 is running ,thread 2 count = 165 thread 2 is running ,thread 2 count = 170 thread 2 is running ,thread 2 count = 175 thread 2 is running ,thread 2 count = 180 thread 2 is running ,thread 2 count = 185 thread 2 is running ,thread 2 count = 190 thread 2 is running ,thread 2 count = 195 thread 2 is running ,thread 2 count = 200 thread 2 is running ,thread 2 count = 205 msh > ``` 代码使用例程代码 ```c #include
#define THREAD_STACK_SIZE 1024 #define THREAD_PRIORITY 20 #define THREAD_TIMESLICE 10 /* 线程入口 */ static void thread_entry(void* parameter) { rt_uint32_t value; rt_uint32_t count = 0; value = (rt_uint32_t)parameter; while (1) { if(0 == (count % 5)) { rt_kprintf("thread %d is running ,thread %d count = %d\n", value , value , count); if(count > 200) return; } count++; } } int timeslice_sample(void) { rt_thread_t tid; /* 创建线程1 */ tid = rt_thread_create("thread1", thread_entry, (void*)1, THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE); if (tid != RT_NULL) rt_thread_startup(tid); /* 创建线程2 */ tid = rt_thread_create("thread2", thread_entry, (void*)2, THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE-5); if (tid != RT_NULL) rt_thread_startup(tid); return 0; } /* 导出到 msh 命令列表中 */ MSH_CMD_EXPORT(timeslice_sample, timeslice sample); ``` rtconfig.h ```c /* RT-Thread config file */ #ifndef __RTTHREAD_CFG_H__ #define __RTTHREAD_CFG_H__ #if defined(__CC_ARM) || defined(__CLANG_ARM) #include "RTE_Components.h" #if defined(RTE_USING_FINSH) #define RT_USING_FINSH #endif //RTE_USING_FINSH #endif //(__CC_ARM) || (__CLANG_ARM) // <<< Use Configuration Wizard in Context Menu >>> //
Basic Configuration //
Maximal level of thread priority <8-256> //
Default: 32 #define RT_THREAD_PRIORITY_MAX 32 //
OS tick per second //
Default: 1000 (1ms) #define RT_TICK_PER_SECOND 1000 //
Alignment size for CPU architecture data access //
Default: 4 #define RT_ALIGN_SIZE 4 //
the max length of object name<2-16> //
Default: 8 #define RT_NAME_MAX 8 //
Using RT-Thread components initialization //
Using RT-Thread components initialization #define RT_USING_COMPONENTS_INIT // #define RT_USING_USER_MAIN //
the stack size of main thread<1-4086> //
Default: 512 #define RT_MAIN_THREAD_STACK_SIZE 256 //
//
Debug Configuration //
enable kernel debug configuration //
Default: enable kernel debug configuration #define RT_DEBUG // //
enable components initialization debug configuration<0-1> //
Default: 0 #define RT_DEBUG_INIT 1 //
thread stack over flow detect //
Diable Thread stack over flow detect #define RT_USING_OVERFLOW_CHECK // //
//
Hook Configuration //
using hook //
using hook //#define RT_USING_HOOK // //
using idle hook //
using idle hook //#define RT_USING_IDLE_HOOK // //
//
Software timers Configuration //
Enables user timers #define RT_USING_TIMER_SOFT 0 #if RT_USING_TIMER_SOFT == 0 #undef RT_USING_TIMER_SOFT #endif //
The priority level of timer thread <0-31> //
Default: 4 #define RT_TIMER_THREAD_PRIO 4 //
The stack size of timer thread <0-8192> //
Default: 512 #define RT_TIMER_THREAD_STACK_SIZE 512 //
//
IPC(Inter-process communication) Configuration //
Using Semaphore //
Using Semaphore #define RT_USING_SEMAPHORE // //
Using Mutex //
Using Mutex //#define RT_USING_MUTEX // //
Using Event //
Using Event //#define RT_USING_EVENT // //
Using MailBox //
Using MailBox #define RT_USING_MAILBOX // //
Using Message Queue //
Using Message Queue //#define RT_USING_MESSAGEQUEUE // //
//
Memory Management Configuration //
Dynamic Heap Management //
Dynamic Heap Management #define RT_USING_HEAP // //
using small memory //
using small memory #define RT_USING_SMALL_MEM // //
using tiny size of memory //
using tiny size of memory //#define RT_USING_TINY_SIZE // //
//
Console Configuration //
Using console //
Using console #define RT_USING_CONSOLE // //
the buffer size of console <1-1024> //
the buffer size of console //
Default: 128 (128Byte) #define RT_CONSOLEBUF_SIZE 128 //
#if defined(RT_USING_FINSH) #define FINSH_USING_MSH #define FINSH_USING_MSH_ONLY //
Finsh Configuration //
the priority of finsh thread <1-7> //
the priority of finsh thread //
Default: 6 #define __FINSH_THREAD_PRIORITY 5 #define FINSH_THREAD_PRIORITY (RT_THREAD_PRIORITY_MAX / 8 * __FINSH_THREAD_PRIORITY + 1) //
the stack of finsh thread <1-4096> //
the stack of finsh thread //
Default: 4096 (4096Byte) #define FINSH_THREAD_STACK_SIZE 4096 //
the history lines of finsh thread <1-32> //
the history lines of finsh thread //
Default: 5 #define FINSH_HISTORY_LINES 5 #define FINSH_USING_SYMTAB //
#endif // <<< end of configuration section >>> #endif ``` 请问时间片为什么不起作用
查看更多
yangjie
认证专家
2020-07-24
hello
怀疑移植的时候时钟没配
3
个回答
默认排序
按发布时间排序
bernard
2020-07-24
这家伙很懒,什么也没写!
为什么没起作用,从log信息看起作用了的
cheney
2020-07-24
这家伙很懒,什么也没写!
我的理解,同优先级的情况下,线程1和线程2都处于就绪态的情况下,只有线程1的时间片跑完的情况下才会去跑线程2,而上面的设置的时间片为10,也就是线程1在10个os_tick后才会去跑线程2,如果一个os_tick为1ms,也就是线程1会在10ms后才会去切换线程2,而count加到200应该是不需要到10ms的,这也就是会出现先线程1跑完后再跑线程2.
撰写答案
登录
注册新账号
关注者
0
被浏览
1.4k
关于作者
autodevice
这家伙很懒,什么也没写!
提问
1
回答
4
被采纳
0
关注TA
发私信
相关问题
1
rt-thread中怎么获取shell中的数据?
2
M4 nano shell 配置后 只有一个高优先级线程工作
3
程序跑飞了,msh发命令进不了shell 大循环,一直在idle里
4
动态切换console到另一个串口该怎么操作
5
Keil AC6, Nano 的 FinSH 功能失效了,怎么恢复正常?
6
有什么方便使用shell的串口调试工具吗
7
finsh shell能在网口上吗?或者在串口和网口上能做动态切换
8
shell指令串口和数据口使用同一个口的问题
9
struct finsh_shell 结构体
10
shell的线程函数实现可能导致线程一直运行
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
国产MCU移植系列教程汇总,欢迎查看!
4
机器人操作系统 (ROS2) 和 RT-Thread 通信
5
五分钟玩转RT-Thread新社区
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
最新文章
1
使用百度AI助手辅助编写一个rt-thread下的ONVIF设备发现功能的功能代码
2
RT-Thread 发布 EtherKit开源以太网硬件!
3
rt-thread使用cherryusb实现虚拟串口
4
《C++20 图形界面程序:速度与渲染效率的双重优化秘籍》
5
《原子操作:程序世界里的“最小魔法单位”解析》
热门标签
RT-Thread Studio
串口
Env
LWIP
SPI
AT
Bootloader
Hardfault
CAN总线
FinSH
ART-Pi
USB
DMA
文件系统
RT-Thread
SCons
RT-Thread Nano
线程
MQTT
STM32
RTC
FAL
rt-smart
ESP8266
I2C_IIC
WIZnet_W5500
UART
ota在线升级
PWM
cubemx
freemodbus
flash
packages_软件包
BSP
潘多拉开发板_Pandora
定时器
ADC
GD32
flashDB
socket
中断
Debug
编译报错
msh
SFUD
keil_MDK
rt_mq_消息队列_msg_queue
at_device
ulog
C++_cpp
本月问答贡献
踩姑娘的小蘑菇
7
个答案
3
次被采纳
a1012112796
13
个答案
2
次被采纳
张世争
9
个答案
2
次被采纳
rv666
5
个答案
2
次被采纳
用户名由3_15位
11
个答案
1
次被采纳
本月文章贡献
程序员阿伟
7
篇文章
2
次点赞
hhart
3
篇文章
4
次点赞
大龄码农
1
篇文章
2
次点赞
ThinkCode
1
篇文章
1
次点赞
Betrayer
1
篇文章
1
次点赞
回到
顶部
发布
问题
分享
好友
手机
浏览
扫码手机浏览
投诉
建议
回到
底部