Writing Solaris Device Driver: Properties

本文介绍设备属性的概念及其在DDI/DKI接口中的应用。包括设备属性的创建、更新、查询及删除等操作,并提供了多种类型属性的示例。

Properties

Properties are user-defined, name-value pair structures that are managed using the DDI/DKI interfaces. This chapter provides information on the following subjects:

Device Properties

Device attribute information can be represented by a name-value pair notation called a property.

For example, device registers and onboard memory can be represented by the reg property. The reg property is a software abstraction that describes device hardware registers. The value of the reg property encodes the device register address location and size. Drivers use the reg property to access device registers.

Another example is the interrupt property. An interrupt property represents the device interrupt. The value of the interrupt property encodes the device-interrupt PIN.

Five types of values can be assigned to properties:

  • Byte array – Series of bytes of an arbitrary length

  • Integer property – An integer value

  • Integer array property – An array of integers

  • String property – A NULL-terminated string

  • String array property – A list of NULL-terminated strings

A property that has no value is considered to be a Boolean property. A Boolean property that exists is true. A Boolean value that does not exist is false.

Device Property Names

Strictly speaking, DDI/DKI software property names have no restrictions. Certain uses are recommended, however. The IEEE 1275-1994 Standard for Boot Firmware defines properties as follows:

A property is a human readable text string consisting of from 1 to 31 printable characters. Property names shall not contain upper case characters or the characters “/”, “/”, “:”, “[“, “]” and “@”. Property names beginning with the character “+” are reserved for use by future revisions of IEEE 1275-1994.

By convention, underscores are not used in property names. Use a hyphen (-) instead. By convention, property names ending with the question mark character (?) contain values that are strings, typically TRUE or FALSE, for example auto-boot?.

Predefined property names are listed in publications of the IEEE 1275 Working Group. See http://playground.sun.com/1275 for information about how to obtain these publications. For a discussion of adding properties in driver configuration files, see the driver.conf(4) man page. The pm(9P) and pm-components(9P) man pages show how properties are used in power management. Read the sd(7D) man page as an example of how properties should be documented in device driver man pages.

Creating and Updating Properties

To create a property for a driver, or to update an existing property, use an interface from the DDI driver update interfaces such as ddi_prop_update_int(9F) or ddi_prop_update_string(9F) with the appropriate property type. See Table 4–1 for a list of available property interfaces. These interfaces are typically called from the driver's attach(9E) entry point. In the following example, ddi_prop_update_string()creates a string property called pm-hardware-state with a value of needs-suspend-resume.

     /* The following code is to tell cpr that this device
* needs to be suspended and resumed.
*/
(void) ddi_prop_update_string(device, dip,
"pm-hardware-state", "needs-suspend-resume");

In most cases, using a ddi_prop_update() routine is sufficient for updating a property. Sometimes, however, the overhead of updating a property value that is subject to frequent change can cause performance problems. See prop_op() Entry Point for a description of using a local instance of a property value to avoid using ddi_prop_update().

Looking Up Properties

A driver can request a property from its parent, which in turn can ask its parent. The driver can control whether the request can go higher than its parent.

For example, the esp driver in the following example maintains an integer property called targetx-sync-speed for each target. The x in targetx-sync-speed represents the target number. The prtconf(1M) command displays driver properties in verbose mode. The following example shows a partial listing for the esp driver.


% prtconf -v
[...]
esp, instance #0
Driver software properties:
name <target2-sync-speed> length <4>
value <0x00000fa0>.
[...]

The following table provides a summary of the property interfaces.

Table 4–1 Property Interface Uses

Family 

Property Interfaces 

Description 

ddi_prop_lookup

ddi_prop_exists(9F)

Looks up a property and returns successfully if the property exists. Fails if the property does not exist 

 

ddi_prop_get_int(9F)

Looks up and returns an integer property 

 

ddi_prop_get_int64(9F)

Looks up and returns a 64-bit integer property 

 

ddi_prop_lookup_int_array(9F)

Looks up and returns an integer array property 

 

ddi_prop_lookup_int64_array(9F)

Looks up and returns a 64-bit integer array property 

 

ddi_prop_lookup_string(9F)

Looks up and returns a string property 

 

ddi_prop_lookup_string_array(9F)

Looks up and returns a string array property 

 

ddi_prop_lookup_byte_array(9F)

Looks up and returns a byte array property 

ddi_prop_update

ddi_prop_update_int(9F)

Updates or creates an integer property 

 

ddi_prop_update_int64(9F)

Updates or creates a single 64-bit integer property 

 

ddi_prop_update_int_array(9F)

Updates or creates an integer array property 

 

ddi_prop_update_string(9F)

Updates or creates a string property 

 

ddi_prop_update_string_array(9F)

Updates or creates a string array property 

 

ddi_prop_update_int64_array(9F)

Updates or creates a 64-bit integer array property 

 

ddi_prop_update_byte_array(9F)

Updates or creates a byte array property 

ddi_prop_remove

ddi_prop_remove(9F)

Removes a property 

 

ddi_prop_remove_all(9F)

Removes all properties that are associated with a device 

Whenever possible, use 64-bit versions of int property interfaces such as ddi_prop_update_int64(9F) instead of 32-bit versions such as ddi_prop_update_int(9F)).

prop_op() Entry Point

The prop_op(9E) entry point is generally required for reporting device properties or driver properties to the system. If the driver does not need to create or manage its own properties, then the ddi_prop_op(9F) function can be used for this entry point.

ddi_prop_op(9F) can be used as the prop_op(9E) entry point for a device driver when ddi_prop_op() is defined in the driver's cb_ops(9S) structure. ddi_prop_op() enables a leaf device to search for and obtain property values from the device's property list.

If the driver has to maintain a property whose value changes frequently, you should define a driver-specific prop_op() routine within the cb_ops structure instead of calling ddi_prop_op(). This technique avoids the inefficiency of using ddi_prop_update() repeatedly. The driver should then maintain a copy of the property value either within its soft-state structure or in a driver variable.

The prop_op(9E) entry point reports the values of specific driver properties and device properties to the system. In many cases, the ddi_prop_op(9F) routine can be used as the driver's prop_op() entry point in the cb_ops(9S) structure. ddi_prop_op() performs all of the required processing. ddi_prop_op() is sufficient for drivers that do not require special processing when handling device property requests.

However, sometimes the driver must provide a prop_op() entry point. For example, if a driver maintains a property whose value changes frequently, updating the property with ddi_prop_update(9F) for each change is not efficient. Instead, the driver should maintain a shadow copy of the property in the instance's soft state. The driver would then update the shadow copy when the value changes without using any of the ddi_prop_update() routines. The prop_op() entry point must intercept requests for this property and use one of the ddi_prop_update() routines to update the value of the property before passing the request to ddi_prop_op() to process the property request.

In the following example, prop_op() intercepts requests for the temperature property. The driver updates a variable in the state structure whenever the property changes. However, the property is updated only when a request is made. The driver then uses ddi_prop_op() to process the property request. If the property request is not specific to a device, the driver does not intercept the request. This situation is indicated when the value of the dev parameter is equal to DDI_DEV_T_ANY, the wildcard device number.


Example 4–1 prop_op() Routine

static int
xx_prop_op(dev_t dev, dev_info_t *dip, ddi_prop_op_t prop_op,
int flags, char *name, caddr_t valuep, int *lengthp)
{
minor_t instance;
struct xxstate *xsp;
if (dev != DDI_DEV_T_ANY) {
return (ddi_prop_op(dev, dip, prop_op, flags, name,
valuep, lengthp));
}

instance = getminor(dev);
xsp = ddi_get_soft_state(statep, instance);
if (xsp == NULL)
return (DDI_PROP_NOTFOUND);
if (strcmp(name, "temperature") == 0) {
ddi_prop_update_int(dev, dip, name, temperature);
}

/* other cases */
}
 
【无人机】基于改进粒子群算法的无人机路径规划研究[和遗传算法、粒子群算法进行比较](Matlab代码实现)内容概要:本文围绕基于改进粒子群算法的无人机路径规划展开研究,重点探讨了在复杂环境中利用改进粒子群算法(PSO)实现无人机三维路径规划的方法,并将其与遗传算法(GA)、标准粒子群算法等传统优化算法进行对比分析。研究内容涵盖路径规划的多目标优化、避障策略、航路点约束以及算法收敛性和寻优能力的评估,所有实验均通过Matlab代码实现,提供了完整的仿真验证流程。文章还提到了多种智能优化算法在无人机路径规划中的应用比较,突出了改进PSO在收敛速度和全局寻优方面的优势。; 适合人群:具备一定Matlab编程基础和优化算法知识的研究生、科研人员及从事无人机路径规划、智能优化算法研究的相关技术人员。; 使用场景及目标:①用于无人机在复杂地形或动态环境下的三维路径规划仿真研究;②比较不同智能优化算法(如PSO、GA、蚁群算法、RRT等)在路径规划中的性能差异;③为多目标优化问题提供算法选型和改进思路。; 阅读建议:建议读者结合文中提供的Matlab代码进行实践操作,重点关注算法的参数设置、适应度函数设计及路径约束处理方式,同时可参考文中提到的多种算法对比思路,拓展到其他智能优化算法的研究与改进中。
<think>我们正在处理用户关于编译过程中遇到“No spaceleft ondevice”错误的问题。这个错误通常意味着磁盘空间不足,导致无法写入生成的汇编文件。我们需要提供解决此问题的方法。解决方案步骤:1.确认磁盘空间不足:使用系统命令检查磁盘使用情况。2.清理磁盘空间:删除不必要的文件,如临时文件、缓存、旧的日志文件等。3.扩大磁盘空间(如果需要):如果清理后空间仍然不足,考虑增加磁盘空间(如扩展磁盘分区或使用外部存储)。4.更改编译输出目录:如果可能,将编译输出定向到有足够空间的磁盘分区。我们将详细说明每一步的操作。注意:以下命令在Linux系统中常用,如果用户使用的是其他操作系统,请相应调整。步骤1:检查磁盘空间使用以下命令检查磁盘空间: ```bashdf -h```这个命令会显示每个挂载点的磁盘使用情况,找出空间不足的分区。步骤2:清理磁盘空间根据步骤1中找到的空间不足的分区,进行清理。常见的清理方法包括: -删除临时文件:通常位于`/tmp`目录,可以使用`sudorm -rf /tmp/*`(注意:确保/tmp目录中没有重要文件)。 -清理包管理器的缓存:对于基于Debian的系统(如Ubuntu),使用`sudo apt-getclean`;对于基于RedHat的系统(如Fedora、CentOS),使用`sudoyum cleanall`或`sudodnfclean all`。-删除旧的日志文件:可以删除`/var/log`目录下的旧日志文件,使用`sudo journalctl --vacuum-size=100M`(清理journal日志)或手动删除日志文件(注意:有些日志文件可能很重要,删除前请确认)。 -查找大文件并删除:使用`sudofind/ -typef -size +100M-execls -lh {}\; |sort -k5 -hr`查找大于100MB的文件,然后评估是否可以删除。步骤3:扩大磁盘空间(可选)如果清理后空间仍然不足,可以考虑:-扩展磁盘分区(如果使用虚拟机或物理机且有未分配空间)。 -挂载新的磁盘分区。 -使用云存储或外部存储。步骤4:更改编译输出目录如果另一个分区有足够的空间,可以将编译输出目录更改到该分区。例如,在编译时指定输出目录: ```bashmake -o/path/to/space_sufficient/directory```或者,如果是在使用cmake,可以在配置时指定输出目录: ```bashcmake-B/path/to/space_sufficient/directory```另外,如果用户正在使用Docker等容器,可能需要检查容器内的磁盘空间,或者将输出目录映射到宿主机上有足够空间的目录。注意事项:-在删除文件前,请确保文件不再需要,以免造成数据丢失。 -清理系统文件时,最好先备份重要数据。如果以上步骤不能解决问题,可能需要进一步分析系统日志或编译日志。生成相关问题:1.如何检查Linux系统中各个目录的磁盘使用情况?2.有哪些安全的方法可以清理Ubuntu系统的磁盘空间?3.如何扩展Linux系统的磁盘分区?4.在编译大型项目时,如何避免磁盘空间不足的问题?5.如何将编译输出重定向到另一个磁盘分区?我们提供了解决“No spaceleft ondevice”错误的基本步骤,用户可以根据具体情况选择操作。</think>### 解决“Error while writing generated assembler file: No space left on device”错误 此错误表明磁盘空间不足,导致编译器无法生成汇编文件。以下是系统性的解决方案: #### 1. **确认磁盘空间状态** ```bash df -h # 查看磁盘分区使用情况 du -sh /path/to/build_dir # 检查编译目录大小 ``` 重点关注`/tmp`、`/var`和项目目录所在分区的剩余空间。 #### 2. **立即释放空间** - **清理临时文件**: ```bash sudo rm -rf /tmp/* # 清除系统临时文件 rm -rf ~/.cache/* # 清除用户缓存 ``` - **删除旧编译产物**: ```bash make clean # 清理项目构建缓存 rm -rf build/ # 删除整个构建目录 ``` - **清理包管理器缓存**: ```apt sudo apt clean # Debian/Ubuntu sudo dnf clean all # Fedora/CentOS ``` #### 3. **定位大文件** ```bash sudo du -h / | grep '[0-9]G\b' # 查找大于1GB的文件 find / -type f -size +500M -exec ls -lh {} \; # 查找>500MB文件 ``` #### 4. **扩展可用空间** - **挂载新存储**: ```bash mkdir /mnt/build_space mount /dev/sdX1 /mnt/build_space # 挂载新磁盘 export TMPDIR=/mnt/build_space # 重定向临时目录 ``` - **调整编译输出路径**: ```bash ./configure --prefix=/mnt/build_space # 配置新安装路径 make -C /mnt/build_space # 指定构建目录 ``` #### 5. **优化编译过程** - **减少中间文件**: ```bash make -j4 # 限制并行编译进程数 strip binaries # 移除调试符号 ``` - **使用符号链接**: ```bash ln -s /mnt/space/tmp /project/tmp # 将临时目录链接到大空间分区 ``` #### 6. **预防措施** ```bash # 添加磁盘监控到cron */10 * * * * df -h | mail -s "Disk Report" admin@example.com # 设置编译自动清理 alias make='make && make clean-objs' ``` > **关键提示**: > - Docker用户需检查容器卷空间:`docker system prune -af` > - 云环境可动态扩展磁盘:AWS EBS/GCP Persistent Disk > - 持续集成环境中设置构建后自动清理[^1]
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值