当前位置: 首页 > news >正文

Linux设备模型(十) - bus/device/device_driver/class

四,驱动的注册

1,struct device_driver结构体

/**
* struct device_driver - The basic device driver structure
* @name:    Name of the device driver.
* @bus:    The bus which the device of this driver belongs to.
* @owner:    The module owner.
* @mod_name:    Used for built-in modules.
* @suppress_bind_attrs: Disables bind/unbind via sysfs.
* @probe_type:    Type of the probe (synchronous or asynchronous) to use.
* @of_match_table: The open firmware table.
* @acpi_match_table: The ACPI match table.
* @probe:    Called to query the existence of a specific device,
*        whether this driver can work with it, and bind the driver
*        to a specific device.
* @sync_state:    Called to sync device state to software state after all the
*        state tracking consumers linked to this device (present at
*        the time of late_initcall) have successfully bound to a
*        driver. If the device has no consumers, this function will
*        be called at late_initcall_sync level. If the device has
*        consumers that are never bound to a driver, this function
*        will never get called until they do.
* @remove:    Called when the device is removed from the system to
*        unbind a device from this driver.
* @shutdown:    Called at shut-down time to quiesce the device.
* @suspend:    Called to put the device to sleep mode. Usually to a
*        low power state.
* @resume:    Called to bring a device from sleep mode.
* @groups:    Default attributes that get created by the driver core
*        automatically.
* @dev_groups:    Additional attributes attached to device instance once the
*        it is bound to the driver.
* @pm:        Power management operations of the device which matched
*        this driver.
* @coredump:    Called when sysfs entry is written to. The device driver
*        is expected to call the dev_coredump API resulting in a
*        uevent.
* @p:        Driver core's private data, no one other than the driver
*        core can touch this.
*
* The device driver-model tracks all of the drivers known to the system.
* The main reason for this tracking is to enable the driver core to match
* up drivers with new devices. Once drivers are known objects within the
* system, however, a number of other things become possible. Device drivers
* can export information and configuration variables that are independent
* of any specific device.
*/
struct device_driver {const char        *name; //该driver的名称struct bus_type        *bus; //该driver所驱动设备的总线struct module        *owner;const char        *mod_name;    /* used for built-in modules */bool suppress_bind_attrs;    /* disables bind/unbind via sysfs */ /* 在kernel中,bind/unbind是从用户空间手动的为driver绑定/解绑定指定的设备的机制 */enum probe_type probe_type;const struct of_device_id    *of_match_table;const struct acpi_device_id    *acpi_match_table;int (*probe) (struct device *dev); /* probe、remove,这两个接口函数用于实现driver逻辑的开始和结束。Driver是一段软件code,因此会有开始和结束两个代码逻辑,就像PC程序,会有一个main函数,main函数的开始就是开始,return的地方就是结束。而内核driver却有其特殊性:在设备模型的结构下,只有driver和device同时存在时,才需要开始执行driver的代码逻辑。这也是probe和remove两个接口名称的由来:检测到了设备和移除了设备(就是为热拔插起的!) */void (*sync_state)(struct device *dev);int (*remove) (struct device *dev);void (*shutdown) (struct device *dev); //电源管理相关int (*suspend) (struct device *dev, pm_message_t state);int (*resume) (struct device *dev);const struct attribute_group **groups; /* 默认的attribute,在driver注册到内核时,内核设备模型部分的代码(driver/base/driver.c)会自动将这些attribute添加到sysfs中 */const struct attribute_group **dev_groups;const struct dev_pm_ops *pm;void (*coredump) (struct device *dev);struct driver_private *p; //driver core的私有数据指针,其它模块不能访问ANDROID_KABI_RESERVE(1);ANDROID_KABI_RESERVE(2);ANDROID_KABI_RESERVE(3);ANDROID_KABI_RESERVE(4);
};

driver的私有数据driver_private:

struct driver_private {struct kobject kobj; //该数据结构对应的struct kobject,代表自身struct klist klist_devices; //该driver驱动的所有设备的链表struct klist_node knode_bus; //用来挂接到bus的driver liststruct module_kobject *mkobj;struct device_driver *driver; //回指到本结构体};

2,driver_register()流程

清晰分解图:

  

3,关键代码流程分析

/* driver_register */

int driver_register(struct device_driver *drv)
{int ret;struct device_driver *other;if (!drv->bus->p) {pr_err("Driver '%s' was unable to register with bus_type '%s' because the bus was not initialized.\n",drv->name, drv->bus->name);return -EINVAL; //如果bus未被初始化退出注册driver}if ((drv->bus->probe && drv->probe) ||(drv->bus->remove && drv->remove) ||(drv->bus->shutdown && drv->shutdown)) //driver和bus的同名操作函数如果同时存在,会出现警告,并且会优先选用bus的pr_warn("Driver '%s' needs updating - please use ""bus_type methods\n", drv->name);other = driver_find(drv->name, drv->bus); //进入bus的driver链表,确认该driver是否已经注册if (other) {pr_err("Error: Driver '%s' is already registered, ""aborting...\n", drv->name); //该driver已经被注册,退出return -EBUSY;}ret = bus_add_driver(drv); //如果没有被注册,就把该driver加入所在busif (ret)return ret;ret = driver_add_groups(drv, drv->groups); //创建attribute文件if (ret) {bus_remove_driver(drv);return ret;}kobject_uevent(&drv->p->kobj, KOBJ_ADD); //该driver已被成功注册,发出KOBJ_ADD ueventreturn ret;
}

/* driver_find */

struct device_driver *driver_find(const char *name, struct bus_type *bus)
{struct kobject *k = kset_find_obj(bus->p->drivers_kset, name); /* bus->p->drivers_kset代表bus下的driver目录,此处会遍历kset->list,该list中包含了所有的挂接到该bus上的driver的kobject,然后通过比较driver内嵌的kobj名字,就是通过kset与kobj之间的关系来查找 */struct driver_private *priv;if (k) {/* Drop reference added by kset_find_obj() */kobject_put(k); //减少kobject的引用计数priv = to_driver(k);return priv->driver; //如果找到同名的kobj就返回该driver}return NULL;
}

/* kset_find_obj */

struct kobject *kset_find_obj(struct kset *kset, const char *name)
{struct kobject *k;struct kobject *ret = NULL;spin_lock(&kset->list_lock);list_for_each_entry(k, &kset->list, entry) { //遍历kset->list链表,取出其中的每一个kobjif (kobject_name(k) && !strcmp(kobject_name(k), name)) { //比较取出的kobj的名字跟指定的kobj的名字是否一致ret = kobject_get_unless_zero(k); //找到匹配的kobj把该driver的kobj引用计数+1并返回break;}}spin_unlock(&kset->list_lock);return ret;
}

/* bus_add_driver */

int bus_add_driver(struct device_driver *drv)
{struct bus_type *bus;struct driver_private *priv;int error = 0;bus = bus_get(drv->bus); //取得其所在bus的指针if (!bus)return -EINVAL;pr_debug("bus: '%s': add driver %s\n", bus->name, drv->name);priv = kzalloc(sizeof(*priv), GFP_KERNEL); //开始初始化这个driver的私有成员if (!priv) {error = -ENOMEM;goto out_put_bus;}klist_init(&priv->klist_devices, NULL, NULL);priv->driver = drv; //回指到本结构体drv->p = priv; //给driver的私有数据赋值priv->kobj.kset = bus->p->drivers_kset; //本driver的kobject属于bus的drivers_kseterror = kobject_init_and_add(&priv->kobj, &driver_ktype, NULL,"%s", drv->name); //初始化driver的kobject并在sysfs中创建目录结构if (error)goto out_unregister;klist_add_tail(&priv->knode_bus, &bus->p->klist_drivers); //将该driver挂接在bus的drivers listif (drv->bus->p->drivers_autoprobe) { error = driver_attach(drv); //如果device与driver自动probe的flag为真,那么到bus的devices上去匹配设备if (error)goto out_del_list;}module_add_driver(drv->owner, drv);error = driver_create_file(drv, &driver_attr_uevent); //创建uevent attribute, /sys/bus/platform/drivers/gpio-keys/ueventif (error) {printk(KERN_ERR "%s: uevent attr (%s) failed\n",__func__, drv->name);}error = driver_add_groups(drv, bus->drv_groups); //创建默认的drv_groups attributesif (error) {/* How the hell do we get out of this pickle? Give up */printk(KERN_ERR "%s: driver_create_groups(%s) failed\n",__func__, drv->name);}if (!drv->suppress_bind_attrs) {error = add_bind_files(drv); /* 创建手动device与driver的bind/unbind的文件节点, /sys/bus/platform/drivers/gpio-keys/bind, /sys/bus/platform/drivers/gpio-keys/unbind */if (error) {/* Ditto */printk(KERN_ERR "%s: add_bind_files(%s) failed\n",__func__, drv->name);}}return 0;out_del_list:klist_del(&priv->knode_bus);
out_unregister:kobject_put(&priv->kobj);/* drv->p is freed in driver_release()  */drv->p = NULL;
out_put_bus:bus_put(bus);return error;
}

/* driver_attach */

int driver_attach(struct device_driver *drv)
{return bus_for_each_dev(drv->bus, NULL, drv, __driver_attach); /* 遍历bus的设备链表找到合适的设备就调用__driver_attach,NULL表示从头开始遍历 */
}

/* bus_for_each_dev */

int bus_for_each_dev(struct bus_type *bus, struct device *start,void *data, int (*fn)(struct device *, void *))
{struct klist_iter i;struct device *dev;int error = 0;if (!bus || !bus->p)return -EINVAL;klist_iter_init_node(&bus->p->klist_devices, &i,(start ? &start->p->knode_bus : NULL)); //进入bus的devices链表while (!error && (dev = next_device(&i))) //设备存在则调用fn即__driver_attach进行匹配error = fn(dev, data);klist_iter_exit(&i);return error;
}

/* __driver_attach */

static int __driver_attach(struct device *dev, void *data)
{struct device_driver *drv = data;bool async = false;int ret;/** Lock device and try to bind to it. We drop the error* here and always return 0, because we need to keep trying* to bind to devices and some drivers will return an error* simply if it didn't support the device.** driver_probe_device() will spit a warning if there* is an error.*/ret = driver_match_device(drv, dev); /* bus的match存在就用bus的,否则就直接匹配成功,match通常实现为首先扫描driver支持的id设备表,如果为NULL就用名字进行匹配 */if (ret == 0) {/* no match */return 0;} else if (ret == -EPROBE_DEFER) {dev_dbg(dev, "Device match requests probe deferral\n");driver_deferred_probe_add(dev);/** Driver could not match with device, but may match with* another device on the bus.*/return 0;} else if (ret < 0) {dev_dbg(dev, "Bus failed to match device: %d\n", ret);return ret;} /* ret > 0 means positive match */if (driver_allows_async_probing(drv)) {/** Instead of probing the device synchronously we will* probe it asynchronously to allow for more parallelism.** We only take the device lock here in order to guarantee* that the dev->driver and async_driver fields are protected*/dev_dbg(dev, "probing driver %s asynchronously\n", drv->name);device_lock(dev);if (!dev->driver) {get_device(dev);dev->p->async_driver = drv;async = true;}device_unlock(dev);if (async)async_schedule_dev(__driver_attach_async_helper, dev);return 0;}device_driver_attach(drv, dev); //匹配成功,将driver与device绑定return 0;
}

/* device_driver_attach */

int device_driver_attach(struct device_driver *drv, struct device *dev)
{int ret = 0;__device_driver_lock(dev, dev->parent);/** If device has been removed or someone has already successfully* bound a driver before us just skip the driver probe call.*/if (!dev->p->dead && !dev->driver)ret = driver_probe_device(drv, dev); //driver与device绑定操作跟之前device注册流程中的一致,后面不再分析__device_driver_unlock(dev, dev->parent);return ret;
}

总结一下,driver的注册,主要涉及将自身挂接到bus的driver链表,并将匹配到的设备加入自己的device链表,并且将匹配到的 device的driver成员初始化为该driver,私有属性的driver节点也挂到driver的设备链表下,其中匹配函数是利用利用bus的 match函数,该函数通常判断如果driver有id表,就查表匹配,如果没有就用driver和device名字匹配。bus的probe优先级始终高于driver的。另外注意一点driver是没有总的起始端点的,driver不是 可具体描述的事物。

五,class

1,class概述

在设备模型中,Bus、Device、Device driver等等,都比较好理解,因为它们对应了实实在在的东西,所有的逻辑都是围绕着这些实体展开的。而本文所要描述的Class就有些不同了,因为它是虚拟出来的,只是为了抽象设备的共性。

举个例子,一些年龄相仿、需要获取的知识相似的人,聚在一起学习,就构成了一个班级(Class)。这个班级可以有自己的名称(如295),但如果离开构成它的学生(device),它就没有任何存在意义。另外,班级存在的最大意义是什么呢?是由老师讲授的每一个课程!因为老师只需要讲一遍,一个班的学生都可以听到。不然的话(例如每个学生都在家学习),就要为每人请一个老师,讲授一遍。而讲的内容,大多是一样的,这就是极大的浪费。

设备模型中的Class所提供的功能也一样了,例如一些相似的device(学生),需要向用户空间提供相似的接口(课程),如果每个设备的驱动都实现一遍的话,就会导致内核有大量的冗余代码,这就是极大的浪费。所以,Class说了,我帮你们实现吧,你们会用就行了。

2,struct class结构体

msm_kernel\include\linux\device\class.h
/**
* struct class - device classes
* @name:    Name of the class.
* @owner:    The module owner.
* @class_groups: Default attributes of this class.
* @dev_groups:    Default attributes of the devices that belong to the class.
* @dev_kobj:    The kobject that represents this class and links it into the hierarchy.
* @dev_uevent:    Called when a device is added, removed from this class, or a
*        few other things that generate uevents to add the environment
*        variables.
* @devnode:    Callback to provide the devtmpfs.
* @class_release: Called to release this class.
* @dev_release: Called to release the device.
* @shutdown_pre: Called at shut-down time before driver shutdown.
* @ns_type:    Callbacks so sysfs can detemine namespaces.
* @namespace:    Namespace of the device belongs to this class.
* @get_ownership: Allows class to specify uid/gid of the sysfs directories
*        for the devices belonging to the class. Usually tied to
*        device's namespace.
* @pm:        The default device power management operations of this class.
* @p:        The private data of the driver core, no one other than the
*        driver core can touch this.
*
* A class is a higher-level view of a device that abstracts out low-level
* implementation details. Drivers may see a SCSI disk or an ATA disk, but,
* at the class level, they are all simply disks. Classes allow user space
* to work with devices based on what they do, rather than how they are
* connected or how they work.
*/
struct class {const char        *name; //class的名称,会在“/sys/class/”目录下体现struct module        *owner; //class所属的模块,虽然class是涉及一类设备,但也是由相应的模块注册的。比如usb类就是由usb模块注册的const struct attribute_group    **class_groups; /* 该class的默认attribute,会在class注册到内核时,自动在“/sys/class/xxx_class”下创建对应的attribute文件 */const struct attribute_group    **dev_groups; /* 该class下每个设备的attribute,会在设备注册到内核时,自动在该设备的sysfs目录下创建对应的attribute文件 */struct kobject            *dev_kobj; /* 表示该class下的设备在/sys/dev/下的目录,现在一般有char和block两个,如果dev_kobj为NULL,则默认选择char */int (*dev_uevent)(struct device *dev, struct kobj_uevent_env *env); /* 当该class下有设备发生变化时,会调用class的uevent回调函数 */char *(*devnode)(struct device *dev, umode_t *mode);void (*class_release)(struct class *class); //用于release自身的回调函数void (*dev_release)(struct device *dev); /* 用于release class内设备的回调函数。在device_release接口中,会依次检查Device、Device Type以及Device所在的class,是否注册release接口,如果有则调用相应的release接口release设备指针 */int (*shutdown_pre)(struct device *dev);const struct kobj_ns_type_operations *ns_type;const void *(*namespace)(struct device *dev);void (*get_ownership)(struct device *dev, kuid_t *uid, kgid_t *gid);const struct dev_pm_ops *pm;struct subsys_private *p; //私有数据,和struct bus_type中的subsys_private一致ANDROID_KABI_RESERVE(1);ANDROID_KABI_RESERVE(2);ANDROID_KABI_RESERVE(3);ANDROID_KABI_RESERVE(4);
};

struct class_interface:

struct class_interface是这样的一个结构:它允许class driver在class下有设备添加或移除的时候,调用预先设置好的回调函数(add_dev和remove_dev)。那调用它们做什么呢?想做什么都行(例如修改设备的名称),由具体的class driver实现。

该结构的定义如下:

struct class_interface {struct list_head    node;struct class        *class;int (*add_dev)        (struct device *, struct class_interface *);void (*remove_dev)    (struct device *, struct class_interface *);
};

3,class创建流程

4,device注册时,和class有关的动作

4.1 调用device_add_class_symlinks接口,创建device与class之间的各种符号链接
static int device_add_class_symlinks(struct device *dev)
{struct device_node *of_node = dev_of_node(dev);int error;if (of_node) {error = sysfs_create_link(&dev->kobj, of_node_kobj(of_node), "of_node");if (error)dev_warn(dev, "Error %d creating of_node link\n",error);/* An error here doesn't warrant bringing down the device */}if (!dev->class)return 0;error = sysfs_create_link(&dev->kobj,&dev->class->p->subsys.kobj,"subsystem"); /* 在该设备所在的sysfs目录创建到该设备所在的class目录的链接,链接名字为subsystem eg: /sys/devices/platform/soc/994000.qcom,qup_uart/tty/ttyMSM0/sussystem -> ../../../../../../class/tty ; /sys/devices/platform/soc/99c000.qcom,qup_uart/tty/ttyHS0/subsystem -> ../../../../../../class/tty */if (error)goto out_devnode;if (dev->parent && device_is_not_partition(dev)) {error = sysfs_create_link(&dev->kobj, &dev->parent->kobj,"device");if (error)goto out_subsys;}#ifdef CONFIG_BLOCK/* /sys/block has directories and does not need symlinks */if (sysfs_deprecated && dev->class == &block_class)return 0;
#endif/* link in the class directory pointing to the device */error = sysfs_create_link(&dev->class->p->subsys.kobj,&dev->kobj, dev_name(dev)); /* 在该设备所在的class目录创建到该设备所在目录的链接,链接名字为设备的名字,eg: /sys/class/tty/ttyMSM0 -> ../../devices/platform/soc/994000.qcom,qup_uart/tty/ttyMSM0 ; /sys/class/tty/ttyHS0 -> ../../devices/platform/soc/99c000.qcom,qup_uart/tty/ttyHS0 */if (error)goto out_device;return 0;out_device:sysfs_remove_link(&dev->kobj, "device");out_subsys:sysfs_remove_link(&dev->kobj, "subsystem");
out_devnode:sysfs_remove_link(&dev->kobj, "of_node");return error;
}
4.2 调用device_add_attrs,添加由class指定的attributes(class->dev_attrs)
static int device_add_attrs(struct device *dev)
->struct class *class = dev->class;if (class) {error = device_add_groups(dev, class->dev_groups);if (error)return error;}
4.3 如果存在对应该class的add_dev回调函数,调用该回调函数
    struct class_interface *class_intf;if (dev->class) {mutex_lock(&dev->class->p->mutex);/* tie the class to the device */klist_add_tail(&dev->p->knode_class,&dev->class->p->klist_devices);/* notify any interfaces that the device is here */list_for_each_entry(class_intf,&dev->class->p->interfaces, node)if (class_intf->add_dev)class_intf->add_dev(dev, class_intf);mutex_unlock(&dev->class->p->mutex);}

5,应用示例

5.1 使用class_create()创建一个class,并在class中创建一个设备
struct class *sec_class;
struct device *factory_ts_dev;sec_class = class_create(THIS_MODULE, "tsp");factory_ts_dev = device_create(sec_class, NULL, 0, info, "tsp");
if (unlikely(!factory_ts_dev)) {dev_err(&info->client->dev, "Failed to create factory dev\n");ret = -ENODEV;goto err_create_device;
}ret = sysfs_create_group(&factory_ts_dev->kobj, &ts_attr_group);
if (unlikely(ret)) {dev_err(&info->client->dev, "Failed to create ts sysfs group\n");goto err_create_sysfs;
}
5.2 使用device_register()在已存在的class目录创建一个设备
info->dev.class = sec_class;
info->dev.parent = &info->client->dev;
info->dev.release = bt541_registered_release;dev_set_name(&info->dev, "tsp_%d", 1);
dev_set_drvdata(&info->dev, info);ret = device_register(&info->dev);
if (ret) {dev_err(&info->client->dev,"%s: Failed to register device\n",__func__);
}ret = device_create_bin_file(&info->dev, &attr_data);
if (ret < 0) {dev_err(&info->client->dev,"%s: Failed to create sysfs bin file\n",__func__);
}

show result info:

lynkco:/sys/class/tsp # ls -l //链接到实际的device

total 0

lrwxrwxrwx 1 root root 0 2023-09-11 15:00 tsp -> ../../devices/virtual/tsp/tsp

lrwxrwxrwx 1 root root 0 2023-09-11 15:00 tsp_1 -> ../../devices/platform/soc/984000.i2c/i2c-2/2-0020/tsp/tsp_1

lynkco:/sys/class/tsp/tsp # ls -l

total 0

-rw-rw-r-- 1 root        root   4096 2023-09-11 15:40 bigobject_off

--w--w---- 1 vendor_tcmd system 4096 2023-09-11 13:09 cmd

-r--r----- 1 vendor_tcmd system 4096 2023-09-11 13:09 cmd_result

-r--r--r-- 1 root        root   4096 2023-09-11 15:40 cmd_status

-rw-rw-r-- 1 root        root   4096 2023-09-11 15:40 easy_wakeup_gesture

lrwxrwxrwx 1 root        root      0 2023-09-11 15:40 input -> ../../../platform/soc/984000.i2c/i2c-2/2-0020/input/input12

drwxr-xr-x 2 root        root      0 2023-09-11 15:40 power

-r--r----- 1 vendor_tcmd system 4096 2023-09-11 13:09 raw_data

-r--r----- 1 vendor_tcmd system 4096 2023-09-11 13:09 short_data

lrwxrwxrwx 1 root        root      0 2023-09-11 15:40 subsystem -> ../../../../class/tsp

-rw-r--r-- 1 root        root   4096 2023-09-11 15:40 uevent

 

 

lynkco:/sys/class/tsp/tsp_1 # ls -l

total 0

-rw-rw-r-- 1 root root    0 2023-09-11 15:40 data

lrwxrwxrwx 1 root root    0 2023-09-11 15:40 device -> ../../../2-0020

drwxr-xr-x 2 root root    0 2023-09-11 15:40 power

lrwxrwxrwx 1 root root    0 2023-09-11 15:40 subsystem -> ../../../../../../../../class/tsp

-rw-r--r-- 1 root root 4096 2023-09-11 15:40 uevent

 

六,通过实例来看bus/device/device_driver/class在sysfs中的关系

1,device,/sys/devices/platform/soc/soc:gpio_keys

虚线表示软连接。

2,device,/sys/devices/platform/soc/994000.qcom,qup_uart

device,/sys/devices/platform/soc/99c000.qcom,qup_uart

参考链接:

Linux设备模型(5)_device和device driver

【Linux内核|驱动模型】bus/class/device/driver - 知乎

Linux的设备驱动模型 - 知乎

https://www.cnblogs.com/bcfx/articles/2915120.html

相关文章:

Linux设备模型(十) - bus/device/device_driver/class

四&#xff0c;驱动的注册 1&#xff0c;struct device_driver结构体 /** * struct device_driver - The basic device driver structure * name: Name of the device driver. * bus: The bus which the device of this driver belongs to. * owner: The module own…...

性能问题分析排查思路之机器(3)

本文是性能问题分析排查思路的展开内容之一&#xff0c;第2篇&#xff0c;主要分为日志1期&#xff0c;机器4期、环境2期共7篇系列文章&#xff0c;本期是第三篇&#xff0c;讲机器&#xff08;硬件&#xff09;的网络方面的排查方法和最佳实践。 主要内容如图所示&#xff1a…...

PostgreSQL安装教程

系统环境 下载压缩包 下载压缩包 解压压缩包 查看解压文件 编译安装 编译 安装 用户权限和环境变量设置 创建用户 创建数据目录和日志目录 设置权限 设置环境变量 初始化数据库 数据库访问控制配置文件 postgresql.conf pg_hba.conf PostgreSQL启动与关闭 手…...

SLAM基础知识:前端和后端

在SLAM中前端和后端是被经常提到的一个概念。但是对于前端和后端的理解有着不同的看法&#xff0c;我的理解是&#xff1a; 前端&#xff1a;前端负责处理传感器数据&#xff0c;特征提取&#xff0c;进行状态估计和地图构建的初步步骤。 后端&#xff1a;后端接受不同时刻的里…...

一文彻底搞懂从输入URL到显示页面的全过程

简略版&#xff1a; 用户输入URL后&#xff0c;浏览器经过URL解析、DNS解析、建立TCP连接、发起HTTP请求、服务器处理请求、接收响应并渲染页面、关闭TCP连接等步骤&#xff0c;最终将页面显示给用户。 详细版&#xff1a; URL解析&#xff1a;浏览器根据用户输入的URL&#x…...

好书安利:《大模型应用开发极简入门:基于GPT-4和ChatGPT》这本书太好了!150页就能让你上手大模型应用开发

文章目录 前言一、ChatGPT 出现&#xff0c;一切都变得不一样了二、蛇尾书特色三、蛇尾书思维导图四、作译者简介五、业内专家书评总结 前言 ​如果问个问题&#xff1a;有哪些产品曾经创造了伟大的奇迹&#xff1f;ChatGPT 应该会当之无愧入选。仅仅发布 5 天&#xff0c;Chat…...

力扣题库第4题:移动零

题目内容&#xff1a; 给定一个数组 nums&#xff0c;编写一个函数将所有 0 移动到数组的末尾&#xff0c;同时保持非零元素的相对顺序。 请注意 &#xff0c;必须在不复制数组的情况下原地对数组进行操作。 示例 : 输入: nums [0,1,0,3,12] 输出: [1,3,12,0,0] 答案&…...

Java解决IP地址无效化

Java解决IP地址无效化 01 题目 给你一个有效的 IPv4 地址 address&#xff0c;返回这个 IP 地址的无效化版本。 所谓无效化 IP 地址&#xff0c;其实就是用 "[.]" 代替了每个 "."。 示例 1&#xff1a; 输入&#xff1a;address "1.1.1.1" 输出…...

[数据结构初阶]队列

鼠鼠我呀&#xff0c;今天写一个基于C语言关于队列的博客&#xff0c;如果有兴趣的读者老爷可以抽空看看&#xff0c;很希望的到各位老爷观点和点评捏&#xff01; 在此今日&#xff0c;也祝各位小姐姐女生节快乐啊&#xff0c;愿笑容依旧灿烂如初阳&#xff0c;勇气与童真永不…...

MySQL学习Day27——MySQL事务日志

事务的隔离性由锁机制实现,而事务的原子性、一致性和持久性由事务的redo日志和undo日志来保证。其中REDO LOG称为重做日志,提供再写入操作,恢复提交事务修改的页操作,用来保证事务的持久性,redo log是存储引擎层生成的日志,记录的是物理级别上的页修改操作,主要为了保证…...

ETAS工具链ISOLAR-AB重要概念,RTE配置,ECU抽取

RTE配置界面&#xff0c;包含ECU抽取关联 首次配置RTE&#xff0c;出现需要勾选的抽取EXTRACT 创建System System制作SWC到ECU的Mapping System制作System Data 的Mapping...

蓝桥杯倒计时 43天 - 前缀和

思路&#xff1a;如果用n^2复杂度暴力会超时。nlogn 可以&#xff0c;利用前缀和化简&#xff0c;提前存储某个位置前的每个石头搬运到该位置和每个石头后搬运到该位置的前缀和On最后直接输出 On。排序花 nlogn #include<bits/stdc.h> using namespace std; typedef pai…...

【Web - 框架 - Vue】随笔 - Vue的简单使用(01) - 快速上手

【Web - 框架 - Vue】随笔 - Vue的简单使用(01) - 快速上手 Vue模板代码 代码 <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><title>模板</title> </head> <body> <div></di…...

【简说八股】Redisson的守护线程是怎么实现的

Redisson Redisson 是一个 Java 语言实现的 Redis SDK 客户端&#xff0c;在使用分布式锁时&#xff0c;它就采用了「自动续期」的方案来避免锁过期&#xff0c;这个守护线程我们一般也把它叫做「看门狗」线程。 Redission是一个在Java环境中使用的开源的分布式缓存和分布式锁实…...

WPS/Office 好用的Word插件-查找替换

例如&#xff1a;一片文档&#xff1a;…………泰山…………泰&#xff08;少打了山字&#xff09;………… 要是把“泰”查找替换为“泰山”&#xff0c;就会把前面的“泰山”变成“泰山山”&#xff0c;这种问题除了再把“泰山山”查找替换为“泰山”&#xff0c;有没有更简单…...

Go 简单设计和实现可扩展、高性能的泛型本地缓存

相信大家对于缓存这个词都不陌生&#xff0c;但凡追求高性能的业务场景&#xff0c;一般都会使用缓存&#xff0c;它可以提高数据的检索速度&#xff0c;减少数据库的压力。缓存大体分为两类&#xff1a;本地缓存和分布式缓存&#xff08;如 Redis&#xff09;。本地缓存适用于…...

Vue.js 深度解析:模板编译原理与过程

&#x1f90d; 前端开发工程师、技术日更博主、已过CET6 &#x1f368; 阿珊和她的猫_CSDN博客专家、23年度博客之星前端领域TOP1 &#x1f560; 牛客高级专题作者、打造专栏《前端面试必备》 、《2024面试高频手撕题》 &#x1f35a; 蓝桥云课签约作者、上架课程《Vue.js 和 E…...

Java多线程——如何保证原子性

目录 引出原子性保障原子性CAS 创建线程有几种方式&#xff1f;方式1&#xff1a;继承Thread创建线程方式2&#xff1a;通过Runnable方式3&#xff1a;通过Callable创建线程方式4&#xff1a;通过线程池概述ThreadPoolExecutor API代码实现源码分析工作原理&#xff1a;线程池的…...

stm32消息和邮箱使用

邮箱管里介绍 邮箱是C/OS-II中另一种通讯机制,它可以使一个任务或者中断服务子程序向另一个任务发送一个指针型的变量。该指针指向一个包含了特定“消息”的数据结构。为了在C/OS-II中使用邮箱,必须将OS_CFG.H中的OS_MBOX_EN常数置为1。使用邮箱之前,必须先建立该邮箱。该操…...

银行数字化转型导师坚鹏:银行数字化转型案例研究

银行数字化转型案例研究 课程背景&#xff1a; 数字化背景下&#xff0c;很多银行存在以下问题&#xff1a; 不清楚银行科技金融数智化案例&#xff1f; 不清楚银行供应链金融数智化案例&#xff1f; 不清楚银行普惠金融数智化案例&#xff1f; 不清楚银行跨境金融数智…...

Linux应用开发之网络套接字编程(实例篇)

服务端与客户端单连接 服务端代码 #include <sys/socket.h> #include <sys/types.h> #include <netinet/in.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <arpa/inet.h> #include <pthread.h> …...

<6>-MySQL表的增删查改

目录 一&#xff0c;create&#xff08;创建表&#xff09; 二&#xff0c;retrieve&#xff08;查询表&#xff09; 1&#xff0c;select列 2&#xff0c;where条件 三&#xff0c;update&#xff08;更新表&#xff09; 四&#xff0c;delete&#xff08;删除表&#xf…...

React Native 开发环境搭建(全平台详解)

React Native 开发环境搭建&#xff08;全平台详解&#xff09; 在开始使用 React Native 开发移动应用之前&#xff0c;正确设置开发环境是至关重要的一步。本文将为你提供一份全面的指南&#xff0c;涵盖 macOS 和 Windows 平台的配置步骤&#xff0c;如何在 Android 和 iOS…...

边缘计算医疗风险自查APP开发方案

核心目标:在便携设备(智能手表/家用检测仪)部署轻量化疾病预测模型,实现低延迟、隐私安全的实时健康风险评估。 一、技术架构设计 #mermaid-svg-iuNaeeLK2YoFKfao {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg…...

深入浅出:JavaScript 中的 `window.crypto.getRandomValues()` 方法

深入浅出&#xff1a;JavaScript 中的 window.crypto.getRandomValues() 方法 在现代 Web 开发中&#xff0c;随机数的生成看似简单&#xff0c;却隐藏着许多玄机。无论是生成密码、加密密钥&#xff0c;还是创建安全令牌&#xff0c;随机数的质量直接关系到系统的安全性。Jav…...

Linux相关概念和易错知识点(42)(TCP的连接管理、可靠性、面临复杂网络的处理)

目录 1.TCP的连接管理机制&#xff08;1&#xff09;三次握手①握手过程②对握手过程的理解 &#xff08;2&#xff09;四次挥手&#xff08;3&#xff09;握手和挥手的触发&#xff08;4&#xff09;状态切换①挥手过程中状态的切换②握手过程中状态的切换 2.TCP的可靠性&…...

Golang dig框架与GraphQL的完美结合

将 Go 的 Dig 依赖注入框架与 GraphQL 结合使用&#xff0c;可以显著提升应用程序的可维护性、可测试性以及灵活性。 Dig 是一个强大的依赖注入容器&#xff0c;能够帮助开发者更好地管理复杂的依赖关系&#xff0c;而 GraphQL 则是一种用于 API 的查询语言&#xff0c;能够提…...

Python实现prophet 理论及参数优化

文章目录 Prophet理论及模型参数介绍Python代码完整实现prophet 添加外部数据进行模型优化 之前初步学习prophet的时候&#xff0c;写过一篇简单实现&#xff0c;后期随着对该模型的深入研究&#xff0c;本次记录涉及到prophet 的公式以及参数调优&#xff0c;从公式可以更直观…...

linux 错误码总结

1,错误码的概念与作用 在Linux系统中,错误码是系统调用或库函数在执行失败时返回的特定数值,用于指示具体的错误类型。这些错误码通过全局变量errno来存储和传递,errno由操作系统维护,保存最近一次发生的错误信息。值得注意的是,errno的值在每次系统调用或函数调用失败时…...

鸿蒙中用HarmonyOS SDK应用服务 HarmonyOS5开发一个医院查看报告小程序

一、开发环境准备 ​​工具安装​​&#xff1a; 下载安装DevEco Studio 4.0&#xff08;支持HarmonyOS 5&#xff09;配置HarmonyOS SDK 5.0确保Node.js版本≥14 ​​项目初始化​​&#xff1a; ohpm init harmony/hospital-report-app 二、核心功能模块实现 1. 报告列表…...