Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

471
Visualizações
How are dev_*() family functions useful while debugging the Linux kernel?

While searching for techniques to debugging a Linux kernel, one of the ways is to use the dev_*() family functions.

These functions are defined in the /include/linux/device.h file.

The function list is as below:

`dev_emerge()`<br>
`dev_alert()`<br>
`dev_crit()`<br>
`dev_err()`<br>
`dev_warning()`<br>
`dev_notice()`<br>
`dev_info()`<br>

I have already experimented with the pr_*()[pr_emerge(), pr_alert(), pr_crit()...] family functions, which are similar to printk() in some way.

An experiment is done using simple kernel modules where I'm calling these functions. Furthermore I have also gone through a priority of messages displayed in syslog and dmesg (kernel ring buffer depending console_loglevel-a kernel variable).

But I'm unable to understand the use of dev_*() family. I mean, how do I use it in a program to debug kernel functionality?

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

The pr_*() functions are the same as plain printk(), but with the KERN_xxx log level already included.

The dev_*() functions are the same as the corresponding pr_*() functions, but also print identifying information about the struct device.

If your message is related to some device (which is normally the case in drivers), you should use dev_*(). For example, in a USB driver:

struct usb_device *usb_dev;
dev_info(&usb_dev->dev, "hello\n");

struct usb_interface *usb_intf;
dev_info(&usb_intf->dev, "hello\n");

or in a PCI driver:

struct pci_dev *pci;
dev_info(&pci->dev, "hello\n");
over 4 years ago · Santiago Trujillo Relatório

0

dev_* functions are similar to pr_*, but also print some information about device(struct device), passed to them as the first argument. This information may help to filter system log for messages, belonging to concrete device.

So, you can use dev_* function instead of pr_* whenever message is applicable to concrete device(and you have destriptor of it).

over 4 years ago · Santiago Trujillo Relatório

0

Check what it prints yourself with QEMU

This is what it prints for a PCI device:

<6>lkmc_pci 0000:00:04.0: pci_probe

which is of format:

<level><kernel-module> <pci-address>: <message>

So as others said, it gives extra device information compared to a simple printk, namely:

  • kernel module name
  • PCI address

I tested that with QEMU's "edu" device, which is simple educational PCI device, for which I wrote a minimal Linux kernel module.

The key module code is:

static int pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
{   
    dev_info(&(dev->dev), "pci_probe\n");

Character devices don't expose a struct device apparently, so you can't test it that way: How do you get a struct device for a Linux character device

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda