新聞中心
Timer是在Linux內(nèi)核中非常重要的機制之一,它被廣泛應(yīng)用于各種驅(qū)動程序的實現(xiàn)中。在系統(tǒng)中,Timer的作用是用來定期觸發(fā)系統(tǒng)任務(wù)的執(zhí)行,比如定期回收緩存、輪詢數(shù)據(jù)、定時喚醒等。在本文中,我們將深入探討Linux驅(qū)動中的Timer機制,包括Timer的概念、實現(xiàn)方式以及應(yīng)用場景等。

一、概念
Timer是一個時間定時器,它是Linux內(nèi)核內(nèi)置的一種機制。在內(nèi)核中,每個Timer都有一個到期時間,當時間到期時,該Timer會向內(nèi)核注冊的回調(diào)函數(shù)發(fā)送信號。這個回調(diào)函數(shù)通常是驅(qū)動程序中的處理函數(shù),它會根據(jù)這個信號來做相應(yīng)的處理。在Linux驅(qū)動中,Timer被廣泛用于周期性地執(zhí)行一些任務(wù),比如檢查硬件狀態(tài)、輪詢數(shù)據(jù)、定期回收緩存等。
二、實現(xiàn)方式
在Linux內(nèi)核中,Timer有兩種實現(xiàn)方式,一種是使用軟中斷(SoftIRQ)來實現(xiàn)的,另一種是使用工作隊列(Work Queue)來實現(xiàn)的。
1.軟中斷
軟中斷是Linux內(nèi)核的一種機制,它是一種異步的、軟件級別的、低優(yōu)先級的中斷。當CPU在執(zhí)行用戶空間程序時,軟中斷可以立即打斷該程序的執(zhí)行,讓內(nèi)核處理一些高優(yōu)先級的任務(wù)。軟中斷使用的是內(nèi)核線程(kernel thread)的上下文,該線程會在軟中斷發(fā)生時自動調(diào)度執(zhí)行。
在使用軟中斷實現(xiàn)Timer時,內(nèi)核會為每個Timer創(chuàng)建一個相應(yīng)的軟中斷。當Timer到期時,軟中斷會被觸發(fā),內(nèi)核會調(diào)用回調(diào)函數(shù)執(zhí)行相應(yīng)的任務(wù)。在Linux內(nèi)核中,軟中斷的優(yōu)先級相對較低,因此如果需要高實時性,建議使用工作隊列來實現(xiàn)。
2.工作隊列
工作隊列是Linux內(nèi)核提供的一種異步執(zhí)行機制,它主要用于處理一些低優(yōu)先級、非實時的任務(wù)。工作隊列使用的是內(nèi)核線程(kernel thread)的上下文,它們的執(zhí)行順序是不可預(yù)測的,但是可以確保任務(wù)得到執(zhí)行。
在使用工作隊列實現(xiàn)Timer時,驅(qū)動程序會創(chuàng)建一個相應(yīng)的工作隊列。當Timer到期時,工作隊列會被觸發(fā)并立即執(zhí)行相應(yīng)的任務(wù),驅(qū)動程序可以通過工作隊列來實現(xiàn)一些周期性的任務(wù)。
三、應(yīng)用場景
Timer機制在Linux驅(qū)動中有著廣泛的應(yīng)用場景,主要包括以下幾個方面:
1.定期檢查硬件狀態(tài)
比如一些設(shè)備需要周期性地檢查自身的狀態(tài),比如磁盤讀寫狀態(tài)、網(wǎng)絡(luò)連接狀態(tài)等。驅(qū)動程序可以使用Timer來實現(xiàn)這個功能,定期檢查設(shè)備狀態(tài)并向內(nèi)核發(fā)送狀態(tài)變化的信號。
2.輪詢數(shù)據(jù)
比如一些輸入設(shè)備需要輪詢輸入狀態(tài),比如鍵盤、鼠標等。驅(qū)動程序可以使用Timer來實現(xiàn)輪詢功能,定期檢查輸入設(shè)備的狀態(tài)并通知內(nèi)核有新的輸入事件發(fā)生。
3.定期回收緩存
系統(tǒng)中會有一些內(nèi)存緩存用來存儲一些臨時數(shù)據(jù),這些數(shù)據(jù)需要定期回收。驅(qū)動程序可以使用Timer來實現(xiàn)定期回收緩存的功能,避免內(nèi)存泄漏等問題。
4.定時喚醒
在一些省電的場景下,設(shè)備需要在一段時間后喚醒執(zhí)行任務(wù)。驅(qū)動程序可以使用Timer來實現(xiàn)定時喚醒的功能,保證設(shè)備在需要執(zhí)行任務(wù)時能夠被喚醒。
Timer是Linux驅(qū)動中非常重要的機制之一,它通常被用來周期性地執(zhí)行一些任務(wù)。在內(nèi)核中,Timer有兩種實現(xiàn)方式,一種是使用軟中斷(SoftIRQ)來實現(xiàn)的,另一種是使用工作隊列(Work Queue)來實現(xiàn)的。應(yīng)用場景包括定期檢查硬件狀態(tài)、輪詢數(shù)據(jù)、定期回收緩存、定時喚醒等。熟悉Timer機制對于Linux驅(qū)動程序員來說非常重要,它可以幫助他們更好地實現(xiàn)設(shè)備驅(qū)動程序及相關(guān)應(yīng)用。
相關(guān)問題拓展閱讀:
- linux0.11版本中,關(guān)于函數(shù)do_timer的疑問
- 在LINUX中如何加載驅(qū)動網(wǎng)卡
linux0.11版本中,關(guān)于函數(shù)do_timer的疑問
可以去作者論壇提問 oldlinux.org
void do_timer (long cpl){
…
fn = next_timer->fn;
next_timer->fn = NULL;
next_timer = next_timer->next;
(fn)();
…
}
這個函數(shù)中的函數(shù)指針是在函數(shù)void add_timer(long jiffies, void (*fn)(void))中添加的。這個腔廳函數(shù)是供內(nèi)核使用的,用戶空間的函數(shù)是不能調(diào)用add_timer的,也就是說 do_timer (long cpl)函數(shù)中的函數(shù)指針只會指向內(nèi)核里面的函數(shù)。
(我去看了linux0.11的源碼,用的地方確實只有
Floppy.c (kernel\blk_drv):add_timer(2,&transfer);
Floppy.c (kernel\blk_drv):add_timer(ticks_to_floppy_on(current_drive),&floppy_on_interrupt);
Sched.c (kernel):void add_timer(long jiffies, void (*fn)(void))
Sched.h (include\linux):extern void add_timer(long jiffies, void (*fn)(void));
)
所以的你的“內(nèi)核不能直接訪問用戶空州沖間函數(shù)問題”是不存在的。
我也是看到了
這個帖子才想到的冊圓殲。
剛開始學(xué)這個,可能說的不對,多包涵。
樓主你好,我也有相同的困惑,不知道你這個最后找到最終的解釋了沒?
在LINUX中如何加載驅(qū)動網(wǎng)卡
實現(xiàn)是通過虛擬網(wǎng)卡實現(xiàn)的。
若想加載USB無啟盯線網(wǎng)卡,只需要把這個USB設(shè)備和host切斷聯(lián)系,虛殲旁悶擬機的Linux可以自氏彎動的接管這個USB設(shè)備。
就在虛擬機下面的狀態(tài)欄上可以控制設(shè)備歸誰管理。
直接找好對應(yīng)的驅(qū)動 一般都會有readme 或者install 之類的說明文兄巖毀檔來告訴你如何去安裝這個網(wǎng)羨備卡驅(qū)動的
Linux* Base Driver for the Atheros(R) AR8121/AR8113 PCI-E Ethernet Adapter
==========================================================================
Contents
========
– In This Release
– Building and Installation
– Command Line Parameters
– Additional Configurations
– Known Issues
– Support
In This Release
===============
This file describes the Linux* Base Driver for the Atheros(R) AR8121/AR8113 PCI-E
Ethernet Adapter, version 1.0.0.5 This driver supports the 2.4.x and 2.6.x kernels.
This driver is only supported as a loadable module at this time. Atheros is not
supplying patches against the kernel source to allow for static linking of
the driver. For questions related to hardware requirements, refer to the
documentation supplied with your Atheros(R) adapter. All hardware
requirements listed apply to use with Linux.
Building and Installation
=========================
To build a binary RPM* package of this driver, run ‘rpmbuild -tb
‘. Replace with the specific filename of
the driver.
NOTE: For the build to work properly, the currently running kernel MUST match
the version and configuration of the installed kernel sources. If you
have just recompiled the kernel reboot the system now.
RPM functionality has only been tested in Red Hat distributions.
1. Move the base driver tar file to the directory of your choice. For example,
use /home/username/arl1e or /usr/local/src/棗唯arl1e.
2. Untar/unzip archive:
tar zxf arl1e-x.x.x.x.tar.gz
3. Change to the driver src directory:
cd arl1e-x.x.x.x/src/
4. Compile the driver module:
make install
The binary will be installed as:
/lib/modules//kernel/drivers/net/arl1e.o
The install locations listed above are the default locations. They might
not be correct for certain Linux distributions. For more information,
see the ldistrib.txt file included in the driver tar.
5. Install the module:
inod arl1e =
6. Assign an IP address to the interface by entering the following, where
x is the interface number:
ifconfig ethx
7. Verify that the interface works. Enter the following, where
is the IP address for another machine on the same subnet as the interface
that is being tested:
ping
Command Line Parameters
=======================
If the driver is built as a module, the following optional parameters are
used by entering them on the command line with the modprobe or inod command
using this syntax:
modprobe arl1e
inod arl1e
For example, with two L001 PCIE adapters, entering:
inod arl1e TxMemSize=80,128
loads the arl1e driver with 8KB TX memory for the first adapter and 10KB TX memory
for the second adapter.
The default value for each parameter is generally the recommended setting,
unless otherwise noted.
NOTES: A descriptor describes a data buffer and attributes related to the
data buffer. This information is accessed by the hardware.
media_type
Valid Range: 0-4
auto-negotiate at all supported speeds
only link at 1000Mbps Full Duplex
only link at 100Mbps Full Duplex
only link at 100Mbps Half Duplex
only link at 10Mbps Full Duplex
only link at 10Mbps Half Duplex
Default Value: 0
media_type forces the line speed/duplex to the specified value in
megabits per second(Mbps). If this parameter is not specified or is set
to 0 and the link partner is set to auto-negotiate, the board will
auto-detect the correct speed.
int_mod_timer
Valid Range:
Default Value: 100
This value represents the minmum interval between interrupts controller
generated.
RxMemBlock
Valid Range:
Default Value: 64
This value is the number of receice memory block allocated by the driver.
Increasing this value allows the driver to buffer more incoming packets.
Each memory block is 1536 bytes.
NOTE: Depending on the available system resources, the request for a
higher number of receive descriptors may be denied. In this case,
use a lower number.
TxMemSize
Valid Range: 4-64
Default Value: 8
This value is the number KB of tranit memory allocated by the driver.
Increasing this value allows the driver to queue more tranits.
NOTE: Depending on the available system resources, the request for a
higher number of tranit descriptors may be denied. In this case,
use a lower number.
FlashVendor
Valid Range: 0-2
Default Value: 0
This value standards on vendor of spi flash used by the adapter.
0 for Atmel, 1 for SST, 2 for ST
Additional Configurations
=========================
Configuring the Driver on Different Distributions
Configuring a network driver to load properly when the system is started is
distribution dependent. Typically, the configuration process involves adding
an alias line to /etc/modules.conf as well as editing other system startup
scripts and/or configuration files. Many popular Linux distributions ship
with tools to make these changes for you. To learn the proper way to
configure a network device for your system, refer to your distribution
documentation. If during this process you are asked for the driver or module
name, the name for the Linux Base Driver for the Atheros AR8121/AR8113 is arl1e
As an example, if you install the arl1e driver for two AR8121/AR8113 adapters
(eth0 and eth1) and set the speed and duplex to 10full and 100half, add the
following to modules.conf:
alias eth0 arl1e
alias eth1 arl1e
options arl1e Speed=10,100 Duplex=2,1
Viewing Link Messages
Link messages will not be displayed to the console if the distribution is
restricting system messages. In order to see network driver link messages
on your console, set dmesg to eight by entering the following:
dmesg -n 8
NOTE: This setting is not saved across reboots.
Known Issues
============
NOTE: For distribution-specific information, see the ldistrib.txt file
included in the driver tar.
Driver Compilation
——
When trying to compile the driver by running make install, the following
error may occur:
“Linux kernel source not configured – missing version.h”
To solve this issue, create the version.h file by going to the Linux source
tree and entering:
make include/linux/version.h.
Support
=======
For general information, go to the Atheros support website at:
If an issue is identified with the released source code on the supported
kernel with a supported adapter, email the specific information related to
the issue to
License
=======
This software program is released under the terms of a license agreement
between you (‘Licensee’) and Atheros. Do not use or load this software or any
associated materials (collectively, the ‘Software’) until you have carefully
read the full terms and conditions of the LICENSE located in this software
package. By loading or using the Software, you agree to the terms of this
Agreement. If you do not agree with the terms of this Agreement, do not
install or use the Software.
* Other names and brands may be claimed as the property of others.
下載驅(qū)動,解壓,然后進入驅(qū)動所在目錄 運行make install
驅(qū)動就是內(nèi)核模塊。加載內(nèi)核模塊就是加載網(wǎng)卡驅(qū)動!
關(guān)于linux 驅(qū)動 timer的介紹到此就結(jié)束了,不知道你從中找到你需要的信息了嗎 ?如果你還想了解更多這方面的信息,記得收藏關(guān)注本站。
香港服務(wù)器選創(chuàng)新互聯(lián),2H2G首月10元開通。
創(chuàng)新互聯(lián)(www.cdcxhl.com)互聯(lián)網(wǎng)服務(wù)提供商,擁有超過10年的服務(wù)器租用、服務(wù)器托管、云服務(wù)器、虛擬主機、網(wǎng)站系統(tǒng)開發(fā)經(jīng)驗。專業(yè)提供云主機、虛擬主機、域名注冊、VPS主機、云服務(wù)器、香港云服務(wù)器、免備案服務(wù)器等。
網(wǎng)站欄目:深入理解Linux驅(qū)動中的Timer機制(linux驅(qū)動timer)
網(wǎng)站路徑:http://m.fisionsoft.com.cn/article/dppsiij.html


咨詢
建站咨詢
