Linux DMA from User Space-public
- 格式:pdf
- 大小:619.45 KB
- 文档页数:30
Linux内核DMA机制-ShangShuWuDMA允许外围设备和主内存之间直接传输 I/O 数据, DMA 依赖于系统。
每一种体系结构DMA传输不同,编程接口也不同。
数据传输可以以两种方式触发:一种软件请求数据,另一种由硬件异步传输。
在第一种情况下,调用的步骤可以概括如下(以read为例):(1)在进程调用read 时,驱动程序的方法分配一个DMA 缓冲区,随后指示硬件传送它的数据。
进程进入睡眠。
(2)硬件将数据写入 DMA 缓冲区并在完成时产生一个中断。
(3)中断处理程序获得输入数据,应答中断,最后唤醒进程,该进程现在可以读取数据了。
第二种情形是在 DMA 被异步使用时发生的。
以数据采集设备为例:(1)硬件发出中断来通知新的数据已经到达。
(2)中断处理程序分配一个DMA缓冲区。
(3)外围设备将数据写入缓冲区,然后在完成时发出另一个中断。
(4)处理程序利用DMA分发新的数据,唤醒任何相关进程。
网卡传输也是如此,网卡有一个循环缓冲区(通常叫做 DMA 环形缓冲区)建立在与处理器共享的内存中。
每一个输入数据包被放置在环形缓冲区中下一个可用缓冲区,并且发出中断。
然后驱动程序将网络数据包传给内核的其它部分处理,并在环形缓冲区中放置一个新的 DMA 缓冲区。
驱动程序在初始化时分配DMA缓冲区,并使用它们直到停止运行。
DMA控制器依赖于平台硬件,这里只对i386的8237 DMA控制器做简单的说明,它有两个控制器,8个通道,具体说明如下:控制器1: 通道0-3,字节操作, 端口为 00-1F控制器2: 通道 4-7, 字操作, 端口咪 C0-DF- 所有寄存器是8 bit,与传输大小无关。
- 通道 4 被用来将控制器1与控制器2级联起来。
- 通道 0-3 是字节操作,地址/计数都是字节的。
- 通道 5-7 是字操作,地址/计数都是以字为单位的。
- 传输器对于(0-3通道)必须不超过64K的物理边界,对于5-7必须不超过128K边界。
linux dma 使用例程DMA(DirectMemoryAccess,直接内存访问)是一种计算机数据传输技术,允许数据在不经过 CPU 的情况下直接传输到设备或内存中。
这种技术可以提高系统性能和效率,减少 CPU 占用率。
2. DMA 操作流程Linux 系统中,DMA 操作可以通过以下步骤进行:(1)申请 DMA 缓冲区使用 dma_alloc_coherent 函数,可以在内核中申请 DMA 缓冲区。
(2)设置 DMA 控制器通过设置 DMA 控制器,让它知道需要传输的数据、目标地址等信息。
这个过程可以通过调用 DMA API 中的函数来完成。
(3)执行 DMA 传输通过调用 DMA API 中的函数,开始执行 DMA 传输。
(4)释放 DMA 缓冲区在 DMA 传输完成后,应该释放申请的 DMA 缓冲区。
3. DMA 使用例程以下是一个简单的 DMA 使用例程。
该例程包括申请 DMA 缓冲区、设置 DMA 控制器、执行 DMA 传输和释放 DMA 缓冲区四个步骤。
```#include <linux/dma-mapping.h>#include <linux/dmaengine.h>int dma_example(void){struct dma_chan *chan;dma_cookie_t cookie;struct dma_async_tx_descriptor *desc;dma_addr_t dma_addr;void *buf;size_t size = 1024;// 申请 DMA 缓冲区buf = dma_alloc_coherent(NULL, size, &dma_addr,GFP_KERNEL);if (!buf)return -ENOMEM;// 获取 DMA 通道chan = dma_request_chan(NULL, 'dma_example');if (!chan) {dma_free_coherent(NULL, size, buf, dma_addr);return -ENODEV;}// 准备 DMA 传输desc = dmaengine_prep_slave_single(chan, dma_addr, size, DMA_MEM_TO_DEV, 0);if (!desc) {dma_release_channel(chan);dma_free_coherent(NULL, size, buf, dma_addr);return -EIO;}// 执行 DMA 传输cookie = dmaengine_submit(desc);dma_async_issue_pending(chan);dma_sync_wait(chan, cookie);// 释放 DMA 缓冲区dmaengine_terminate_all(chan);dma_release_channel(chan);dma_free_coherent(NULL, size, buf, dma_addr);return 0;}```4. 总结以上是一个简单的 Linux DMA 使用例程。
general setupenable loadable module supportenable the block layerprocessor type and feathurespower management and acpi optionsbus options(pci etc.)executable file formats/emulationsnetworking supportdevice driversfirmware driversfile systemkernel hackingsecurity optionscryptographic apivirtualizationlibrary routinesload an alternate configuration filesave an alternate configuration filegeneral setup(通用配置)Auditing supportEnable system-Call auditing suppRCU Subsystem --->Kernel config supportCoNaUTS namespaceIPC namespaceUser namespace (EXPERIMENTAL)PID Namespaces (EXPERIMENTAL)Network namespaceIn enable loadable module support(启用可加载模块支持)enable the block layer(使阻挡层)processor type and feathures(处理器类型和feathures的)paMemtestProcessor family (Pentium-Pro) Generic xe6 supportPentiumPro memory ordering errat HPET Timer SupportMaximum number of CPUsSMT (Hyperthreading) scheduler Multi-core scheduler support Fine granularity task level IR ReMachin Check / overheating repor Intel MCE featuresAMD MCE featuresMaToshiba Laptop supportDell laptop supportEnable X86 board specific fixups /dev/cpu/microcode - microcode s Intel microcode patch loading su AMD microcode patch loading sup /dev/cpu/*/msr - Model-specific /dev/cpu/*/cpuid - CPU informati High Memory Support (4GB) ---Memory model (Flat Memory) --Enable KSM for page mergingEnPoison pages injectorAllocate 3rd-level pagetables frChReserve low 64K of RAM on RMI/Math emulationMTRR (Memory Type Range RegisteMTRR cleanup supportMTRR cleanup enable value (0-1)MTRR cleanup spare reg num (0-7)x86 PAT supportEFI runtime service supportTikexec system callkernel crash dumpskexec jump (EXPERIMENTAL)Build a relocatable kernelSuCompat VDSO supportpower management and acpi options电源管理和ACPI选项SFI (Simple Firmware Interface) CPbus options(pci etc.)总线选项(PCI等)Support for DMA Remapping DeviceEnable DMA Remapping Devices byPCI Express supportPCI Express Hotplug driverRoot Port Advanced Error ReporPCI Express ECRC settings controPCIE AER error injector supportPCI Express ASPM support(ExperimDebug PCI Express RSPMMessage Signaled Interrupts (MSEnable deprecated pci_find_* APIPCI DebuggingPCI Stub driverInterrupts on hypertransport dePCI IOV supportISA supportEISA supportMCA supportNatSemi SCx200 supporlOnPCCard(PCMCIA/CardBus) support -executable file formats/emulations可执行文件格式/仿真networking support网络支持device drivers设备驱动程序Macintosh device drivers --->Network device support --->ISDN support --->Telephony support --->Input device support --->Character devices --->12C support --->SPI support --->PPS support --->GPDallas's 1-wire support --->Power supply class support ---Hardware Monitoring support --Generic Thermal sysfs driverWatchdog Timer Support --->Sonics Silicon Backplane --->Multifunction device drivers ->Voltage and Current Regulator SuMultimedia support --->Graphics support --->Sound card support --->HID Devices --->USB support --->Ultra Wideband devices (EXPERIMMMC/SD/SDIO card support --->LEAccessibility support --->InfinlBand support --->ReDMA Engine support ---> firmware drivers固件驱动程序file system文件系统JBJBD2 (ext4) debugging support Reiserfs supportReiserfs supportEnable reiserfs debug modeStats in /proc/fs/reiserfs ReiserFS extended attributes ReiserFS POSIX Access Control Li ReiserFS Security LabelsJFS filesystem supportJFS POSIX Access Control Lists JFS Security LabelsJFS debuggingJFS statisticsXFS filesystem supportXFS Quota supportXFS POSIX ACL supportXFS Realtime subvolume support XFS Debugging support (EXPERIME GFS2 file system supportGFS2 DLM lockingOCFS2 file system support02CB Kernelspace Clustering OCFS2 Userspace Clustering OCFS2 statisticsOCFS2 logging supportOCFS2 expensive checksOCFS2 POSIX Access Control Lists BtNILFS2 file system support (EXP Dnotify supportInotify file change notification Inotify support for userspace Quota supportReport quota messages through ne Print quota warnintts to console Old quota format supportQuota format v2 supportKeFUCharacter device in Userpace supCaches --->CD-ROM/DVD Filesystems ->DOS/FAT/NT Filesustems ->Pseudo filesystems --->Miscellaneous filesystems ---> kernel hacking内核黑客Debug shared IRq handlersDetect Soft LockupsPanic (Reboot) On Soft LockupsDetect Hung TasksPanic (Reboot) On Hung TasksCollect scheduler debugging infoCollect scheduler statisticsCollect kernel timers statisticsDebug object operationsSLOB debugging on by defaultEnable SLUB performance statistiKernel memory leak detectorRT Mutex debugging, deadlock detBuilt-in scriptable tester for rSpinlock and rw-lock debugging:Mutex debugging: basic checksLoLock usage statisticsLokobject debuggingHiCompile the kernel with debug in Debug VMDebug VM translationsDebug filesystem writers count Debug linked list manipulatio Debug SG table operationsDebug notifier call chains Debug credential management Compile the kernel with frame po Delay each boot printk message torture tests for RCUCheck for stalled CPUs delaying Kprobes sanity testsSelf test for the backtrace code FoLinux Kernel Dump Test Tool Modu Fault-injection framework Latency measuring infrastructure Sysctl checksDebug page memory allocations Tracers --->Remote debugging over FireWire e Remote debugging over FireWire w Enable dynamic printk() support Enable debugging of DMA-API usa Sample kernel code ---> KGDB: kernel debugging with remo Filter access to /dev/mem Enable verbose x86 bootup info m Early printkEarly printk via EHCI debug port Check for stack overflowsStack utilization instrumentatio Debug access to per_cpu maps Write protect kernel read-only d Testcase for the DEBUG_RODATA fe Testcase for the NX non-executab Use 4Kb for kernel stacks instea Enable IOMMU stress-test modesecurity options安全性选项cryptographic api加密APIAuthenc supportTesting moduleCCGCM/GMAC supportSequence Number IV Generator*** Block modes ***CBC supportCTR supportCTS supportECB supportLRW support (EXPERIMENTAL)PCBC supportXTS Support (EXPERIMENTAL)*** Hash modes ***HMAC SupportXCBC SupportVMAC Support*** Digest ***CRC32c CRC algorithmCRGHASH digest algorithmMD4 digest algorithmMD5 digest algorithmMichael MIC keyed digest algoritRIPEMD-128 digest algorithmRIPEMD-160 digest algorithmRIPEMD-256 digest algorithmRIPEMD-320 digest algorithmSHA1 digest algorithmSHA224 and SHA256 digest algoriSHR384 and SHA512 digest algoriTiger digest algorithmsWhirlpool digest algorithms*** Ciphers ***RES cipher algorithmsRES cipher algorithms (i586)Rnubis cipher algorithmRRC4 cipher algorithmBlowfish cipher algorithmCAST5 (CAST-128) cipher algoriCAST6 (CAST-256) cipher algoritDES and Triple DES EDE cipher alFCrypt cipher algorithmKhazad cipher algorithmSalsa20 stream cipher algorithmSEvirtualization虚拟化library routines库例程load an alternate configuration file加载备用配置文件save an alternate configuration file保存备用配置文件De一般的设置(通用配置)启用可加载模块支持使阻挡层处理器类型和feathures的电源管理和ACPI选项总线选项(PCI等)可执行文件格式/仿真网络支持设备驱动程序固件驱动程序文件系统内核黑客安全性选项加密API虚拟化库例程加载备用配置文件保存备用配置文件Prompt for development and/or incomplete code/dri Local version - append to kernel release Automatically append version information to the vers Kernel compression mode (Gzip) --->Support for paging of anonymous memory (swap) System V IPCPOSIX Message QueuesBSD Process AccountingBSD Process Accounting version 3 file formatExport task/process statistics through netlink (EXP Enable per-task delay accounting (EXPERIMENTAL) Enable extended accounting over taskstats (EXPERIMEN Enable per-task storage I/O accounting (EXPERIMENT Auditing supportEnable system-Call auditing supportRCU Subsystem --->Kernel config supportKernel loft buffer size (16 => 64KB, 17 => 12BKB) Control Group support --->enable deprecated sysfs features which may confuse o Kernel->user space relay support (formerly relayfs) Namespaces supportUTS namespaceIPC namespaceUser namespace (EXPERIMENTAL)PID Namespaces (EXPERIMENTAL)Network namespaceInitial RAM filesystem and RAM disk (initramfs/initInitramfs source file(s)Optimize for sizeConfigure standard kernel features (for small system Kernel Performance Events And Counters ---> Disable heap randomizationChoose SLAB allocator (SLUB (Unqueued Allocator)) Profiling Support (EXPERIMENTAL)OProfile system profiling (EXPERIMENTAL)OProfile RMD IBS Support (EXPERIMENTAL)OProfile multiplexing support (EXPERIMENTAL) KprobesGCOV-based kernel profiling --->Slow work debugging through debugfs--- Enable loadable module supportForced module loadingM_dule unloadingForced module unloadingM dule versioning supportSource checksum for all modules—Enable the block layerSupport for large (2TB+) block devices and files Block layer SG support v4Block layer data integrity supportIO Schedulers --->Tickless System (Dynamic Ticks)High Resolution Timer SupportSymmetric multi-processing supportSupport sparse irq numberingEnable MPS tableSupport for big SMP systems with more than 8 CPUs Support for extended (non-PC) x86 platformsSingle-depth WCHRN outputParavirtualized guest support --->paravirt-ops debuggingMemtestProcessor family (Pentium-Pro) --->Generic xe6 supportPentiumPro memory ordering errata workarouncHPET Timer SupportMaximum number of CPUsSMT (Hyperthreading) scheduler supportMulti-core scheduler supportFine granularity task level IRQ time accounting Preemption Model (Voluntary Kernel Preemption (Des Rerout for broken boot IRQsMachin Check / overheating reportingIntel MCE featuresAMD MCE featuresSupport for old Pentium 5 / WinChip machine checks Machine check injector supportToshiba Laptop supportDell laptop supportEnable X86 board specific fixups for reboot/dev/cpu/microcode - microcode supportIntel microcode patch loading supportAMD microcode patch loading support/dev/cpu/*/msr - Model-specific register support/dev/cpu/*/cpuid - CPU information supportHigh Memory Support (4GB) --->Memory model (Flat Memory) --->Enable KSM for page merging(65536) Low address space to protect from user all Enable recovery from hardware memory errorsPoison pages injectorAllocate 3rd-level pagetables from highmemCheck for low memory corruptionReserve low 64K of RAM on RMI/Phoenix BIOSerMath emulationMTRR (Memory Type Range Register) SupportMTRR cleanup supportMTRR cleanup enable value (0-1)MTRR cleanup spare reg num (0-7)x86 PAT supportEFI runtime service supportEnable seccomp to safely compute untrusted bytecodeEnable -fstack-protector buffer overflow detection (Timer frequency (250 HZ) --->kexec system callkernel crash dumpskexec jump (EXPERIMENTAL)Build a relocatable kernelAlignment value to which kernel should be alignedSupport for hot-pluggable CPUsCompat VDSO supportBuilt-in kernel command linePower Management supportPower Management Debug SupportVerbose Power Management debuggingSuspend/resume event tracingSuspend to RAM and standbyTest suspend/resume and wakealarm during bootupHibernation (aka 'suspend to disk’)Default resume partitionRun-time PM core functionalityACPI (Advanced Configuration and Power Interface)FuDeprecated /proc/acpi/eventAC AdapterBatteryButtonVideoFandirectoriesSupportDockProcessorProcessor AggregatorThDisable ACPI for systems before Jan 1stDebug StatementsPCI slot detection driverSFI (Simple Firmware Interface) Support --->APM (Advanced Power Management) BIOS support --->CPU Frequency scaling --->CPU frequency translation statisticsCPU frequency translation statistics detDefault CPUFreq governor (ondemand) --performance' governorpowersave' governoruserspace' governor for userspace frequondemand' cpufreq policy governorconservative' cpufreq governor*** CPUFreq processor drivers ***ACPI Processor P-States driverAMD Mobile K6-2/K6-3 PowerNow!AMD Mobile Athlon/Duron PowerNow)AMD Opteron/Athlon64 PowerNow!Cyrix MediaGX/NatSemi Geode Suspend ModuIntel Enhanced SpeedStep (deprecated)Built-in tables for Banias CPUsCPU idle PM supportPCI supportPCI access mode (Any) --->Support for DMA Remapping Devices (EXPERIMENTAL) Enable DMA Remapping Devices by defaultPCI Express supportPCI Express Hotplug driverRoot Port Advanced Error Reporting supportPCI Express ECRC settings controlPCIE AER error injector supportPCI Express ASPM support(Experimental)Debug PCI Express RSPMMessage Signaled Interrupts (MSI and MSI-X) Enable deprecated pci_find_* APIPCI DebuggingPCI Stub driverInterrupts on hypertransport devicesPCI IOV supportISA supportEISA supportMCA supportNatSemi SCx200 supporlNatSemi SCx200 27MHz High-Resolution Timer Support One Laptop Per Child supportPCCard(PCMCIA/CardBus) support -->Support for PCI hotplug --->Kernel support for ELF binariesWrite ELF core dumps with partial segmentsKernel support for a.out and ECOFF binariesKernel support for MISS binariesNetworking options --->Amateur Radio support --->CAN bus subsystem support --->IrDA (infrared) subsystem supportBluetooth subsystem support --->RxRPC session socketsRxRPC dynamic debuggingRxRPC Kerberos securityWireless --->WiMAX Wireless Broadband support-->RF switch subsystem support --->Plan 9 Resource Sharing Support (9P2000) (Experime Generic Driver Options --->Connector - unified userspace <-> kernelspace linker Memory Technology Device (MTD) support ---> Parallel port support --->Plug and Play support --->Block devices --->Misc devices --->RTR/RTRPI/MFM/RLL support --->SCSI device support --->Serial PTA (prod) and Parallel PTA (experimental) Multiple devices driver support (RAID and LVM) --Fusion MPT device support --->IEEE 1394 (FireWire) support --->120 device support --->Macintosh device drivers --->Network device support --->ISDN support --->Telephony support --->Input device support --->Character devices --->12C support --->SPI support --->PPS support --->GPIO Support --->Dallas's 1-wire support --->Power supply class support --->Hardware Monitoring support --->Generic Thermal sysfs driverWatchdog Timer Support --->Sonics Silicon Backplane --->Multifunction device drivers ->Voltage and Current Regulator Support--->Multimedia support --->Graphics support --->Sound card support --->HID Devices --->USB support --->Ultra Wideband devices (EXPERIMENTAL) --->MMC/SD/SDIO card support --->Sony MemoryStick card support (EXPERIMENTAL) ---> LED Support --->Accessibility support --->InfinlBand support --->EDAC (Error Detection And Correction) reporting Real Time Clock --->DMA Engine support --->Auxiliary Display support --->Userspace I/D drivers --->TI.VLYNQ --->Staging drivers --->X86 Platform Specific Device DriversBIOS Enhanced Disk Drive calls determine boot disk Sets default behavior for EDD detection to offEFI Variable Support via sysfsBIOS update support for DELL systems via sysfsDell Systems Management Base DriverExport DMI identification via sysfs to userspace iSCSI Boot Firmware Table AttributesiSCSI Boot Firmware Table Attributes moduleSecond extended fs supportExt2 extended attributesExt2 POSIX Access Control ListsExt2 Security LabelsExt2 execute in place supportExt3 journalling file system supportDefault to 'data=ordered' in ext3Ext3 extended attributesExt3 POSIX Access Control ListsExt3 Security LabelsThe Extended 4 (ext4) filesystemExt4 extended attributesExt4 POSIX Access Control ListsExt4 Security LabelsEXT4 debugging supportJBD (ext3) debugging supportJBD2 (ext4) debugging supportReiserfs supportReiserfs supportEnable reiserfs debug modeStats in /proc/fs/reiserfsReiserFS extended attributesReiserFS POSIX Access Control ListsReiserFS Security LabelsJFS filesystem supportJFS POSIX Access Control ListsJFS Security LabelsJFS debuggingJFS statisticsXFS filesystem supportXFS Quota supportXFS POSIX ACL supportXFS Realtime subvolume supportXFS Debugging support (EXPERIMENTAL)GFS2 file system supportGFS2 DLM lockingOCFS2 file system support02CB Kernelspace ClusteringOCFS2 Userspace ClusteringOCFS2 statisticsOCFS2 logging supportOCFS2 expensive checksOCFS2 POSIX Access Control ListsBtrfs filesystem (EXPERIMENTAL) Unstable disk forma Btrfs POSIX Access Control ListsNILFS2 file system support (EXPERIMENTAL)Dnotify supportInotify file change notification supportInotify support for userspaceQuota supportReport quota messages through netlink interfacePrint quota warnintts to console (OBSOLETE)Old quota format supportQuota format v2 supportKernel automounter supportKernel automounter version 4 support (also supports FUSE (Filesystem in Userspace) supportCharacter device in Userpace supportCaches --->CD-ROM/DVD Filesystems ->DOS/FAT/NT Filesustems ->Pseudo filesystems --->Miscellaneous filesystems --->Network File Systems --->Partition Types --->Native language support --->Distributed Lock Manager (DLM) --->Show timing information on printksEnable__deprecated logicEnable--must-check logic(1024) Warn for stack frames larger than (needs gC Magic SysRq Key(OxOlb6) Default mask for Magic SysRq keys on the c Strip assembler-generated symbols during link Enable unused/obsolete exported symbolsDebug FilesystemRun 'make headers_check' when building vmlinux Kernel debuggingDebug shared IRq handlersDetect Soft LockupsPanic (Reboot) On Soft LockupsDetect Hung TasksPanic (Reboot) On Hung TasksCollect scheduler debugging infoCollect scheduler statisticsCollect kernel timers statisticsDebug object operationsSLOB debugging on by defaultEnable SLUB performance statisticsKernel memory leak detectorRT Mutex debugging, deadlock detectionBuilt-in scriptable tester for rt-mutexesSpinlock and rw-lock debugging: basic checksMutex debugging: basic checksLock debugging: detect incorrect freeing of live loc Lock debugging: prove locking correctnessLock usage statisticsSpinlock debugging: sleep-inside-spinlock checking Locking API boot-time self-testskobject debuggingHighmem debuggingCompile the kernel with debug infoDebug VMDebug VM translationsDebug filesystem writers countDebug linked list manipulationDebug SG table operationsDebug notifier call chainsDebug credential managementCompile the kernel with frame pointersDelay each boot printk message by N milliseconds torture tests for RCUCheck for stalled CPUs delaying RCU grace periods Kprobes sanity testsSelf test for the backtrace codeForce extended block device numbers and spread them Force weak per-cpu definitionsLinux Kernel Dump Test Tool ModuleFault-injection frameworkLatency measuring infrastructureSysctl checksDebug page memory allocationsTracers --->Remote debugging over FireWire early on bootRemote debugging over FireWire with firewire-ohci Enable dynamic printk() supportEnable debugging of DMA-API usageSample kernel code --->KGDB: kernel debugging with remote gdb --->Filter access to /dev/memEnable verbose x86 bootup info messagesEarly printkEarly printk via EHCI debug portCheck for stack overflowsStack utilization instrumentationDebug access to per_cpu mapsWrite protect kernel read-only data structures Testcase for the DEBUG_RODATA featureTestcase for the NX non-executable stack feature Use 4Kb for kernel stacks instead of BKbEnable IOMMU stress-test modeID delay type (port 0x80 based port-IO delay [recomm Debug boot parametersCPA self-test codeAllow gcc to uninline functions marked 'inline'Enable the /pros/keys file by which keys may be view Enable different security modelsEnable the securityfs filesystemSocket and Networking Security HooksXFRM (IPSec) Networking Security HooksSecurity hooks for pathname based access controlFile POSIX CapabilitiesEnable Intel(R) Trusted Execution Technology (Int Low address space for LSM to protect from user allo NSR SELinux SupportNSR SELinux boot parameterNSR SELinux boot parameter default valueNSR SELinux runtime disableNSA SELinux Development SupportNSA SELinux AVC StatisticsNSA SELinux checkreqprot default valueNSA SELinux maximum supported policy format version TOMDYO Linux SupportIntegrity Measurement Architecture(IMA)*** Crypto core or helper ***FIPS 200 complianceCryptographic algorithm managerGF(2-128) multiplication functions (EXPERIMENTAL) Null algorithmsSoftware async crypto daemonAuthenc supportTesting module*** Authenticated Encryption with Associated Data ** CCM supportGCM/GMAC supportSequence Number IV Generator*** Block modes ***CBC supportCTR supportCTS supportECB supportLRW support (EXPERIMENTAL)PCBC supportXTS Support (EXPERIMENTAL)*** Hash modes ***HMAC SupportXCBC SupportVMAC Support*** Digest ***CRC32c CRC algorithmCRC32c INTEL hardware accelerationGHASH digest algorithmMD4 digest algorithmMD5 digest algorithmMichael MIC keyed digest algorithmRIPEMD-128 digest algorithmRIPEMD-160 digest algorithmRIPEMD-256 digest algorithmRIPEMD-320 digest algorithmSHA1 digest algorithmSHA224 and SHA256 digest algorithmSHR384 and SHA512 digest algorithmsTiger digest algorithmsWhirlpool digest algorithms*** Ciphers ***RES cipher algorithmsRES cipher algorithms (i586)Rnubis cipher algorithmRRC4 cipher algorithmBlowfish cipher algorithmCAST5 (CAST-128) cipher algorithmCAST6 (CAST-256) cipher algorithmDES and Triple DES EDE cipher algorithmsFCrypt cipher algorithmKhazad cipher algorithmSalsa20 stream cipher algorithm (EXPERIMENTAL)Salsa20 stream cipher algorithm (1586) (EXPERIMENTA SEED cipher algorithmSerpent cipher algorithmTEA, XTEA and XETA cipher algorithmsTwofish cipher algorithmTwofish cipher algorithms (1586)*** Compression ***Deflate compression algorithmlib compression algorithmLZD compression algorithm*** Random Number Generation ***Pseudo Random Number Generation for CrUotoeraohic mo Hardware crypto devices--->Kernel-based Virtual Machine (KVM) SupportKVM for Intel processors supportKVM for AMD processors supportLinux hypervisor example codePCI driver for virtio devices (EXPERIMENTAL)Virtio balloon driver (EXPERIMENTAL)CRC-CCITT functionsCRC16 functionsCRC calculation for the T10 Data Integrity Field CRC ITU-T V.41 functionsCRC32 functionsCRC7 functionsCRC32c (Castagnoli, et al) Cyclic Redundancy-Check 下面是扩展选项,因为太多了所以只列出一部分networking supportDevice Drivers->。
linux 标准dma 测试指令-回复当今计算机系统中,DMA(直接内存访问)是一项重要的技术,它能够大幅提高数据传输的效率。
Linux作为一种主流的操作系统,自然也提供了一系列标准的DMA测试指令,用于检测和评估系统的DMA性能。
本文将一步一步地介绍这些标准的DMA测试指令,以帮助读者更好地了解和使用Linux中的DMA技术。
首先,我们需要明确一下DMA的概念和作用。
DMA是一种数据传输方式,它允许外设(如磁盘控制器、网络适配器等)直接访问主内存,而不需要通过中央处理器进行数据传输。
这样可以极大地减轻CPU的负载,提高数据传输的速度和效率。
在Linux中,DMA技术得到了广泛应用,主要体现在硬盘IO和网络通信中。
接下来,我们将介绍几个常用的Linux标准DMA测试指令。
1. hdparmhdparm是一个常用的硬盘工具,它提供了多种性能测试功能。
通过hdparm命令,我们可以测试硬盘的传输速度、缓存性能等。
在测试DMA性能时,可以用hdparm的-T选项测试硬盘缓存的读取速度,使用-h选项测试硬盘能够达到的最大传输速率。
2. dddd是一个用于数据块传输的命令行工具。
通过dd命令,我们可以测试系统的数据传输速度和TCP/IP网络的性能。
在DMA测试中,可以使用dd命令传输一个大文件或者生成一个大文件,然后通过计算传输速度来评估系统的DMA性能。
示例命令如下:dd if=/dev/zero of=testfile bs=1M count=1000 #生成一个大小为1GB的文件dd if=testfile of=/dev/null bs=1M count=1000 #从文件中读取数据并丢弃通过这两条命令,我们可以测试系统从硬盘读取数据的速度和向硬盘写入数据的速度。
3. iperfiperf是一个用于测量TCP/IP网络性能的工具。
通过iperf命令,我们可以测试网络的带宽、延迟等参数。
在DMA测试中,可以通过iperf在两台计算机之间进行数据传输来评估网络的DMA性能。
linuxDMA接⼝知识点详解1.两种DMA映射类型1.1. ⼀致性DMA映射(Consistent DMA mappings )主要⽤于映射长时间使⽤的区域。
CPU和DMA controller不需要考虑cache的影响。
这⾥的consistent实际上是coherent的概念,不能保证consistent,也就是说需要memory barrier来保证memory order。
1.2 流式DMA映射(streaming DMA mapping)主要⽤于⼀次性DMA传输,传输完成后就会释放。
2.指定DMA设备的寻址范围include/linux/dma-mapping.h// ⽤于⼀致性内存映射的映射范围static inline int dma_set_coherent_mask(struct device *dev, u64 mask)// ⽤于流式内存映射的映射范围static inline int dma_set_mask(struct device *dev, u64 mask);3.DMA映射接⼝3.1⼀致性DMA接⼝分配较⼤DMA buffer// dev DMA控制器设备// size 要分配的DMA buffer⼤⼩// dma_handle 返回DMA buf的物理地址// flag 分配标志// 返回值 DMA buffer的虚拟地址void *dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle, gfp_t flag)// dev DMA控制器设备// size 释放的DMA buffer⼤⼩// cpu_addr DMA buf的虚拟地址// dma_handle DMA buf的物理地址void dma_free_coherent(struct device *dev, size_t size,void *cpu_addr, dma_addr_t dma_handle)分配较⼩DMA buffer,从dma poll中申请。
本文以32位系统为例介绍内核空间(ker n el s pa ce)和用户空间(u se r sp ac e)。
内核空间和用户空间对32位操作系统而言,它的寻址空间(虚拟地址空间,或叫线性地址空间)为4G(2的32次方)。
也就是说一个进程的最大地址空间为4G。
操作系统的核心是内核(ke rn el),它独立于普通的应用程序,可以访问受保护的内存空间,也有访问底层硬件设备的所有权限。
为了保证内核的安全,现在的操作系统一般都强制用户进程不能直接操作内核。
具体的实现方式基本都是由操作系统将虚拟地址空间划分为两部分,一部分为内核空间,另一部分为用户空间。
针对Li nu x 操作系统而言,最高的1G 字节(从虚拟地址0x C0000000到0xF F FF FF FF)由内核使用,称为内核空间。
而较低的 3G字节(从虚拟地址0x00000000到0xB F FF FF FF)由各个进程使用,称为用户空间。
对上面这段内容我们可以这样理解:「每个进程的 4G 地址空间中,最高1G 都是一样的,即内核空间。
只有剩余的 3G 才归进程自己使用。
」「换句话说就是,最高1G 的内核空间是被所有进程共享的!」下图描述了每个进程4G 地址空间的分配情况:为什么需要区分内核空间与用户空间在CP U 的所有指令中,有些指令是非常危险的,如果错用,将导致系统崩溃,比如清内存、设置时钟等。
如果允许所有的程序都可以使用这些指令,那么系统崩溃的概率将大大增加。
所以,C PU将指令分为特权指令和非特权指令,对于那些危险的指令,只允许操作系统及其相关模块使用,普通应用程序只能使用那些不会造成灾难的指令。
比如I nt el 的C PU将特权等级分为4个级别:R in g0~Ri n g3。
其实 L in ux系统只使用了Ri ng0 和Ri n g3两个运行级别(W in do ws系统也是一样的)。
当进程运行在 R in g3级别时被称为运行在用户态,而运行在R i ng0 级别时被称为运行在内核态。
linux 内核空间用户空间跨空间回调函数-回复在操作系统中,Linux 内核空间和用户空间是两个重要的概念。
内核空间是操作系统内核运行的环境,只有内核级别的代码可以在此空间中执行,用户空间是用户程序运行的环境,只有用户级别的代码可以在此空间中执行。
两者之间存在着一道界限,这就是为了保证操作系统的稳定性和安全性。
本文将深入探讨内核空间和用户空间之间的交互方式,特别是跨空间回调函数的作用和实现方式。
一、Linux 内核空间和用户空间的概念和特点Linux 操作系统是一种开源的操作系统,它的内核是单独运行在内核空间中的,而用户程序则运行在用户空间中。
内核空间具有以下特点:1. 内核空间是操作系统的核心组成部分,包括了中断处理、进程管理、内存管理等操作系统的重要功能。
2. 内核空间的代码通常是运行在特权级别最高的模式下,可以直接访问系统的硬件资源。
3. 内核空间的代码由操作系统开发人员编写,由于其权限较高,因此必须经过严格的测试和验证,确保其安全性和稳定性。
相比之下,用户空间具有以下特点:1. 用户空间是用户程序执行的环境,例如应用程序、服务程序等。
2. 用户空间的代码运行在较低的特权级别下,不能直接访问硬件资源,必须通过系统调用等方式与内核空间交互。
3. 用户空间中的代码通常由开发人员编写,不同的用户程序之间可以相互隔离,提高了系统的安全性和稳定性。
二、内核空间和用户空间的交互方式在Linux 操作系统中,内核空间和用户空间之间必须通过一定的机制进行交互。
最常见的交互方式是通过系统调用,用户空间的程序可以通过系统调用请求内核空间的服务。
内核空间会根据系统调用的类型执行相应的操作,并将结果返回给用户空间。
除了系统调用外,内核空间和用户空间还可以通过文件操作、进程间通信等方式进行交互。
这些机制都是为了实现内核空间和用户空间之间的数据传递、权限控制等功能。
三、跨空间回调函数的定义和作用跨空间回调函数是指在内核空间中定义和注册的回调函数,用于处理用户空间发起的某种事件或请求。
3项技术:1,mmap系统调用可以实现将设备内存映射到用户进程的地址空间。
2,使用get_user_pages,可以把用户空间内存映射到内核中。
3,DMA的I/O操作,使得外设具有直接访问系统内存的能力。
-------------内存管理内核用来管理内存的数据结构---------地址内型Linux是一个虚拟内存系统,即用户程序使用的地址与硬件使用的物理地址是不等同的。
虚拟内存引入了一个间接层,使得许多操作成为可能:*有了虚拟内存,系统中运行的程序可以分配比物理内存更多的内存。
*虚拟地址还能让程序在进程的地址空间内使用更多的技巧,包括将程序的内存映射到设备内存上。
地址内型列表*用户虚拟地址每个进程都有自己的虚拟地址空间。
*物理地址处理器访问系统内存时使用的地址。
*总线地址在外围总线和内存之间使用。
MMU可以实现总线和主内存之间的重新映射。
当设置DMA操作时,编写MMU相关的代码是一个必需的步骤。
*内核逻辑地址内核逻辑地址组成了内核的常规地址空间,该地址映射了部分(或全部)内存,并经常被视为物理地址。
在大多数体系架构中,逻辑地址与其相关联的物理地址的不同,仅仅在于它们之间存在一个固定的偏移量。
kmalloc返回的内存就是内核逻辑地址。
*内核虚拟地址内核虚拟地址与逻辑地址相同之处在于,都将内核空间的地址映射到物理地址上。
不同之处在于,内核虚拟地址与物理地址的映射不是线性的和一对一的。
vmalloc返回一个虚拟地址,kmap函数也返回一个虚拟地址。
------------------物理地址和页物理地址被分为离散的单元,称之为页。
系统内部许多对内存的操作都是基于单个页的。
大多数系统都使用每页4096个字节,PAGE_SIZE <asm/page.h>给出指定体系架构下的页大小。
观察内存地址,无论是虚拟的还是物理的,它们都被分为页号和一个页内的偏移量。
如果每页4096个字节,那么最后的12位就是偏移量,剩余的高位则指定页号。
linux简单的DMA例程⼀个简单的使⽤DMA 例⼦⽰例:下⾯是⼀个简单的使⽤DMA进⾏传输的驱动程序,它是⼀个假想的设备,只列出DMA相关的部分来说明驱动程序中如何使⽤DMA 的。
函数dad_transfer是设置DMA对内存buffer的传输操作函数,它使⽤流式映射将buffer的虚拟地址转换到物理地址,设置好DMA控制器,然后开始传输数据。
int dad_transfer(struct dad_dev *dev, int write, void *buffer, size_t count) { dma_addr_t bus_addr; unsigned long flags; /* Map the buffer for DMA */ dev->dma_dir = (write ? PCI_DMA_TODEVICE : PCI_DMA_FROMDEVICE); dev->dma_size = count; //流式映射,将buffer的虚拟地址转化成物理地址 bus_addr = pci_map_single(dev->pci_dev, buffer, count, dev->dma_dir); dev->dma_addr = bus_addr; //DMA传送的buffer物理地址 //将操作控制写⼊到DMA控制器寄存器,从⽽建⽴起设备 writeb(dev->mand, DAD_CMD_DISABLEDMA); //设置传输⽅向--读还是写 writeb(dev->mand, write ? DAD_CMD_WR : DAD_CMD_RD); writel(dev->registers.addr, cpu_to_le32(bus_addr));//buffer物理地址 writel(dev->registers.len, cpu_to_le32(count)); //传输的字节数 //开始激活DMA进⾏数据传输操作 writeb(dev->mand, DAD_CMD_ENABLEDMA); return 0; }函数dad_interrupt是中断处理函数,当DMA传输完时,调⽤这个中断函数来取消buffer上的DMA映射,从⽽让内核程序可以访问这个buffer。
linux dma 的使用流程下载温馨提示:该文档是我店铺精心编制而成,希望大家下载以后,能够帮助大家解决实际的问题。
文档下载后可定制随意修改,请根据实际需要进行相应的调整和使用,谢谢!并且,本店铺为大家提供各种各样类型的实用资料,如教育随笔、日记赏析、句子摘抄、古诗大全、经典美文、话题作文、工作总结、词语解析、文案摘录、其他资料等等,如想了解不同资料格式和写法,敬请关注!Download tips: This document is carefully compiled by theeditor.I hope that after you download them,they can help yousolve practical problems. The document can be customized andmodified after downloading,please adjust and use it according toactual needs, thank you!In addition, our shop provides you with various types ofpractical materials,such as educational essays, diaryappreciation,sentence excerpts,ancient poems,classic articles,topic composition,work summary,word parsing,copy excerpts,other materials and so on,want to know different data formats andwriting methods,please pay attention!Linux DMA 使用流程详解在嵌入式系统和高性能计算领域,Linux 内核中的 Direct Memory Access (DMA) 技术扮演着至关重要的角色,它允许设备直接访问内存,而无需CPU介入数据传输过程。
DMA控制器硬件结构1DMA 通道使用的地址 (3)DMA操作函数 (4)DMA映射 (6)(1 )建立一致DMA映射 (7)(2 )建立流式DMA映射 (8)(3)分散/集中映射 (10)DMA 池 (11)一个简单的使用DMA例子 (15)DMA空制器硬件结构DMA允许外围设备和主内存之间直接传输I/O数据,DMA依赖于系统。
每一种体系结构DMA专输不同,编程接口也不同。
数据传输可以以两种方式触发:一种软件请求数据,另一种由硬件异步传输。
在第一种情况下,调用的步骤可以概括如下(以read为例):(1)在进程调用read时,驱动程序的方法分配一个DMA缓冲区,随后指示硬件传送它的数据。
进程进入睡眠。
(2)硬件将数据写入DMA缓冲区并在完成时产生一个中断。
(3)中断处理程序获得输入数据,应答中断,最后唤醒进程,该进程现在可以读取数据了。
第二种情形是在DMA被异步使用时发生的。
以数据采集设备为例:(1)硬件发出中断来通知新的数据已经到达。
(2)中断处理程序分配一个DMA g冲区。
(3)外围设备将数据写入缓冲区,然后在完成时发出另一个中断。
(4)处理程序利用DMA^发新的数据,唤醒任何相关进程。
网卡传输也是如此,网卡有一个循环缓冲区(通常叫做DMA环形缓冲区)建立在与处理器共享的内存中。
每一个输入数据包被放置在环形缓冲区中下一个可用缓冲区,并且发出中断。
然后驱动程序将网络数据包传给内核的其它部分处理, 并在环形缓冲区中放置一个新的 DMA 缓冲区。
驱动程序在初始化时分配 DMA S 冲区,并使用它们直到停止运行。
DMA 空制器依赖于平台硬件,这里只对i386的8237 DMA 控控制器做简单的说明, 它有两个控制器,8个通道,具体说明如下:控制器1:通道0-3,字节操作,端口为00-仆控制器2:通道4-7,字操作,端口咪C0-DF-所有寄存器是8 bit ,与传输大小无关。
-通道4被用来将控制器1与控制器2级联起来。
linux dma sg原理Linux DMA (Direct Memory Access) SG (Scatter-Gather) 是一种用于在Linux系统中进行高效数据传输的技术。
DMA是一种无需CPU 干预的数据传输方式,而SG则是一种允许数据散布在多个非连续内存块中的传输方式。
本文将介绍Linux DMA SG的原理及其应用。
在计算机系统中,CPU负责执行指令和处理数据,而DMA则是一种机制,允许外部设备直接访问系统内存,而不需要CPU的介入。
这样可以显著提高数据传输的效率。
而SG则是一种允许数据分散在多个非连续内存块中的传输方式。
这在处理大量数据或需要将数据分散存储的情况下非常有用。
Linux中的DMA SG技术利用了这两种机制,以实现高效的数据传输。
在传统的DMA方式中,数据必须连续存储在内存中。
而在SG方式中,数据可以分散存储在多个内存块中,这样可以更灵活地使用内存资源。
在数据传输过程中,SG允许DMA控制器按照一定的顺序从多个内存块中读取数据,然后按照需要传输到外部设备。
在Linux中,DMA SG技术主要通过以下三个组件实现:1. DMA引擎:DMA引擎是一个硬件模块,负责管理和执行DMA传输。
它通常与外部设备(如网卡、磁盘控制器等)紧密集成在一起。
DMA 引擎可以通过DMA控制器寄存器进行配置和控制。
2. DMA缓冲区:DMA缓冲区是一块用于存储数据的内存区域。
在SG方式下,数据可以分散存储在多个非连续的DMA缓冲区中。
每个DMA缓冲区都有一个描述符,包含了该缓冲区的地址和长度信息。
3. DMA映射:DMA映射是一种机制,用于将DMA缓冲区中的物理地址映射到虚拟地址空间中。
这样可以方便CPU和DMA引擎之间的数据交换。
在Linux中,可以使用DMA映射函数进行地址映射操作。
在使用Linux DMA SG技术时,首先需要通过DMA映射函数将DMA缓冲区中的物理地址映射到虚拟地址空间中。
linux用户空间和内核空间之细说Linux简化了分段机制,使得虚拟地址与线性地址总是一致,因此,Linux的虚拟地址空间也为0~4G。
Linux内核将这4G字节的空间分为两部分。
将最高的1G字节(从虚拟地址0xC0000000到0xFFFFFFFF),供内核使用,称为"内核空间"。
而将较低的3G字节(从虚拟地址0x00000000到0xBFFFFFFF),供各个进程使用,称为"用户空间)。
因为每个进程可以通过系统调用进入内核,因此,Linux内核由系统内的所有进程共享。
于是,从具体进程的角度来看,每个进程可以拥有4G字节的虚拟空间。
Linux使用两级保护机制:0级供内核使用,3级供用户程序使用。
从图中可以看出(这里无法表示图),每个进程有各自的私有用户空间(0~3G),这个空间对系统中的其他进程是不可见的。
最高的1GB字节虚拟内核空间则为所有进程以及内核所共享。
1.虚拟内核空间到物理空间的映射内核空间中存放的是内核代码和数据,而进程的用户空间中存放的是用户程序的代码和数据。
不管是内核空间还是用户空间,它们都处于虚拟空间中。
读者会问,系统启动时,内核的代码和数据不是被装入到物理内存吗?它们为什么也处于虚拟内存中呢?这和编译程序有关,后面我们通过具体讨论就会明白这一点。
虽然内核空间占据了每个虚拟空间中的最高1GB字节,但映射到物理内存却总是从最低地址(0x00000000)开始。
对内核空间来说,其地址映射是很简单的线性映射,0xC0000000就是物理地址与线性地址之间的位移量,在Linux代码中就叫做PAGE_OFFSET。
我们来看一下在include/asm/i386/page.h中对内核空间中地址映射的说明及定义:/** This handles the memory map.. We could make this a config* option, but too many people screw it up, and too few need* it.** A __PAGE_OFFSET of 0xC0000000 means that the kernel has * a virtual address space of one gigabyte, which limits the* amount of physical memory you can use to about 950MB.** If you want more physical memory than this then see the CONFIG_HIGHMEM4G * and CONFIG_HIGHMEM64G options in the kernel configuration.*/#define __PAGE_OFFSET (0xC0000000)……#define PAGE_OFFSET ((unsigned long)__PAGE_OFFSET)#define __pa(x) ((unsigned long)(x)-PAGE_OFFSET)#define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET)) 源代码的注释中说明,如果你的物理内存大于950MB,那么在编译内核时就需要加CONFIG_HIGHMEM4G和CONFIG_HIGHMEM64G选项,这种情况我们暂不考虑。
在Linux中,DMA(Direct Memory Access)是一种允许设备直接访问内存的技术。
DMA控制器用于管理这种直接访问,但具体的DMA控制器使用方法因硬件和驱动程序而异。
一般来说,为了使用DMA,需要遵循以下步骤:
1. 确定设备是否支持DMA。
这可以通过检查设备的规格表或相关文档来确认。
2. 配置DMA控制器。
这通常包括设置DMA通道的基地址、大小和其他相关参数。
这些设置通常需要在设备驱动程序中完成。
3. 启动DMA传输。
这通常需要向DMA控制器提交一个描述传输参数的描述符,包括源地址、目标地址、传输大小等。
4. 检查DMA传输的状态。
这可以通过读取DMA控制器的状态寄存器或使用驱动程序提供的接口来完成。
在Linux中,可以使用内核API来访问DMA控制器。
例如,在Linux 2.6内核中,可以使用dma_map_single()函数来映射一块内存用于DMA传输,使用dma_unmap_single()函数来取消内存映射,使用dma_map_sg()函数来映射一个scatter-gather列表用于DMA传输,使用dma_unmap_sg()函数来取消scatter-gather列表的映射。
需要注意的是,由于不同的硬件平台和驱动程序可能有不同的实
现方式,因此在使用DMA时需要参考特定硬件和驱动程序的文档。
小包转发--LINUX的弱项小包转发效率低下,这既不是SYN问题,也与QUEUE无关,根源在于:1、操作系统对大量随机中断(interrpt)的性能低下:PC体系架构的系统中,网卡接收数据(RECV)基于中断机制(IRQ)。
以前窄带时代带宽小,每秒产生IRQ次数少,占用CPU处理资源也就少。
在宽带环境下,当每秒IRQ数量达到10K以上时,CPU就忙不赢了。
2、操作系统从kernel到user-space的内存复制(copy)效率低下。
为解决IRQ处理瓶颈,现代操作系统改变了网卡的IRQ处理机制,提高了网络处理效率:提高网络性能的几种技术1、FreeBSD下的device polling关闭网卡的中断方式,使用轮循方式收发报文,可以大大提高小包(如syn flood,udp flood)下的路由性能和路由器的稳定性,提升率可以超过100M线速。
2、Linux2.6下的NAPI(New API)关闭网卡的中断方式,使用轮循方式收发报文,可以大大提高小包(如syn flood,udp flood)下的路由性能和路由器的稳定性,提升率可以超过100M线速,但远低于FreeBSD下的decice_polling。
3、Linux下的Timer_based网卡驱动程序(Tuplit网卡)关闭网卡的中断方式,使用基于网卡上定时器进行定时查询方式收发报文,可以大大提高小包(如syn flood,udp flood)下的路由性能和路由器的稳定性,提升率可以超过100M线速,但远低于FreeBSD下的decice_polling。
4、Linux下的NAPI和Circular Buffer技术(DMA—user_space技术)关闭网卡的中断方式,使用轮循方式收发报文,可以大大提高小包(如syn flood,udp flood)下的路由性能和路由器的稳定性,提升率可以超过1000M线速,略高于FreeBSD下的decice_polling。
Linux 操作系统和驱动程序运行在内核空间,应用程序运行在用户空间,二者不能简单地利用指针传递数据,因为Linux利用的虚拟内存机制,用户空间的数据可能被换出,当内核空间利用用户空间指针时,对应的数据可能不在内存中。
Linux内核地址映射模型x86 CPU采纳了段页式地址映射模型。
进程代码中的地址为逻辑地址,通过段页式地址映射后,才真正访问物理内存。
段页式机制如以下图。
Linux内核地址空间划分通常32位Linux内核地址空间划分0~3G为用户空间,3~4G为内核空间。
注意那个地址是32位内核地址空间划分,64位内核地址空间划分是不同的。
Linux内核高端内存的由来当内核模块代码或线程访问内存时,代码中的内存地址都为逻辑地址,而对应到真正的物理内存地址,需腹地址一对一的映射,如逻辑地址0xc0000003对应的物理地址为0×3,0xc0000004对应的物理地址为0×4,… …,逻辑地址与物理地址对应的关系为物理地址= 逻辑地址– 0xC0000000假设依照上述简单的地址映射关系,那么内核逻辑地址空间访问为0xc0000000 ~0xffffffff,那么对应的物理内存范围就为0×0 ~ 0×,即只能访问1G物理内存。
假设机械中安装8G物理内存,那么内核就只能访问前1G物理内存,后面7G物理内存将会无法访问,因为内核的地址空间已经全数映射到物理内存地址范围0×0 ~ 0×。
即便安装了8G物理内存,那么物理地址为0×的内存,内核该怎么去访问呢代码中必需要有内存逻辑地址的,0xc0000000 ~ 0xffffffff的地址空间已经被用完了,因此无法访问物理地址0×以后的内存。
显然不能将内核地址空间0xc0000000 ~ 0xfffffff全数用来简单的地址映射。
因此x86架构中将内核地址空间划分三部份:ZONE_DMA、ZONE_NORMAL和ZONE_HIGHMEM。
linux 标准dma 测试指令-回复Linux是一个开源操作系统内核,具有强大的性能和可定制性。
DMA (Direct Memory Access,直接内存访问)是一种技术,用于在计算机系统中实现数据传输,它可以提高性能,减少处理器的负担。
本文将介绍Linux中标准的DMA测试指令,以帮助读者了解如何在Linux系统中进行DMA测试。
DMA允许外设(例如网络适配器、磁盘驱动器等)直接与系统内存进行数据传输,而不需要CPU的直接干预。
这样,CPU就可以处理其他任务,而不必等待数据传输完成。
在Linux中,可以通过多种方式进行DMA测试,包括标准的Linux DMA接口和一些特定的工具。
1. 安装必要的软件在进行DMA测试之前,首先需要安装一些必要的软件包。
常用的软件包有dmatest、stress-ng和perf等。
在大多数Linux发行版中,可以使用包管理器来安装这些软件包。
sudo apt-get install dmatest stress-ng perf这些软件包提供了一些基本的DMA测试工具和性能分析工具。
2. 使用dmatest进行基本DMA测试dmatest是一个简单但强大的工具,用于进行基本的DMA测试。
它可以模拟DMA传输并测试系统的性能。
首先,需要加载dmatest内核模块。
sudo modprobe dmatest然后,使用以下命令运行dmatest。
sudo dmatest -c 1这将执行一次DMA传输,并打印出测试结果。
dmatest还提供了许多选项,可用于自定义测试。
例如,可以指定传输的大小、数量、方向和目的地等。
3. 使用stress-ng进行高负载DMA测试stress-ng是一个全面的系统压力测试工具,可以用于测试系统在高负载情况下的性能。
它可以通过模拟多种负载类型,包括DMA负载,对系统进行测试。
首先,需要加载stress-ng内核模块。
sudo modprobe stress-ng然后,使用以下命令运行stress-ng。
Linux协议栈中UDP数据报从网卡到用户空间流程总结Linux协议栈中UDP数据报从网卡到用户空间流程总结NAPI驱动流程:中断发生-->确定中断原因是数据接收完毕(中断原因也可能是发送完毕,DMA完毕,甚至是中断通道上的其他设备中断)-->通过netif_rx_schedule将驱动自己的napi结构加入softnet_data的poll_list链表,禁用网卡中断,并发出软中断-->中断返回时触发软中断net_rx_action,从softnet_data的poll_list上取下刚挂入的napi结构,并且调用其 poll函数,这个poll 函数也是驱动自己提供的,比如rtl8139网卡驱动中的rtl8139_poll等。
-->在poll函数中进行轮询,直到接受完所有的数据或者预算(budget)耗尽。
每接收一个报文要分配skb,用eth_type_trans处理并交给netif_receive_skb。
-->如果数据全部接收完(预算没有用完),则重新使能中断并将napi从链表中取下。
如果数据没接收完,则什么也不作,等待下一次poll函数被调度。
非NAPI流程:中断发生-->确定中断发生的原因是接收完毕。
分配skb,读入数据,用eth_type_trans处理并且将skb交给netif_rx-->在netif_rx中,将packet加入到softnet_data的input_pkt_queue末尾(NAPI驱动不使用这个input_pkt_queue),再通过napi_schedule将softnet_data中的backlog(这也是个napi 结构)加入 softnet_data的poll_list,最后发出软中断-->软中断net_rx_action从poll_list上取下softnet_data的backlog,调用其poll函数,这个poll函数是内核提供的process_backlog-->函数process_backlog从softnet_data的input_pkt_queue末尾取下skb,并且直接交给netif_receive_skb处理。
linux下DMA操作方式和利弊详解Linux DMA使用(网摘)关键词:0引言1如何在Linux下用DMA的方式进行数据传输(硬盘)我们都知道,使用DMA方式传输数据可以占用更少的CPU资源,因此与其它操作系统一样,Linux支持硬盘以DMA方式转输数据,但在安装Red Hat时关于DMA的默认选项是Disable的,当然你可以在安装时就enable它。
如果在安装时DMA是disable的,那该怎么才能激活DMA呢?通过重新编译内核可以激活DMA支持,但编译内核对新手显然太过复杂。
下面的方法无需编译内核,就可以激活DMA 支持。
一、检查系统中的DMA选项是否已被激活在进行操作前,先确认硬盘是否已经在使用DMA方式传输数据了。
方法:查看/ proc/ide/hda/settings文件,其中有一行的内容为:using_dma,如果其后面的值被设置为1就说明系统已经支持DMA 了,那么下面的操作就可以免了,当然如果你要关闭DMA 功能的话,还要往下看看哟:)。
Linux中的hdparm命令是用来进行与硬盘相关操作的,用hdparm-i/dev/hda可以列出IDE可能支持的DMA模式,如:DMAmodes:mdma0mdma1mdma2udma0udma1udma2udma3*udma4二、激活DMA支持方法1:在lilo.conf中加入:idex=dma,其中x代表硬盘序号,其取值范围0-3,分别代表系统中的四个IDE硬盘设备。
方法2:使用hdparm命令,hdparm d1/dev/hda其中d1表示使能DMA,你可以将其加到rc.locl中以便每次启动时都硬盘都能使用DMA方式传输数据。
三、关闭DMA支持命令格式:hdparm d0/dev/hda关闭DMA传输方式,实在想不出有什么理由要这样做。
对支持UDMA传输方式的硬盘,也可以参照以上的方法进行设置,但要确保硬盘控制器及硬盘都支持UDMA,最后你还要有一根支持UDMA传输方式的硬盘连线,否则即使你激活了UDMA支持,它也会罢工的。