亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 7962 | 回復: 6
打印 上一主題 下一主題

請教個napi_struct 、net_device數(shù)據(jù)結構中與鏈表相關的幾個問題 [復制鏈接]

論壇徽章:
0
跳轉到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2011-04-13 21:30 |只看該作者 |倒序瀏覽
本帖最后由 lofeng410 于 2011-04-19 08:09 編輯

struct napi_struct
        struct list_head        poll_list;        unsigned long                state;
        int                        weight;
        int                        (*poll)(struct napi_struct *, int);
#ifdef CONFIG_NETPOLL
        spinlock_t                poll_lock;
        int                        poll_owner;
#endif

        unsigned int                gro_count;

        struct net_device        *dev;
        struct list_head        dev_list;        struct sk_buff                *gro_list;
        struct sk_buff                *skb;
};
  1. struct net_device
  2. {
  3.                struct list_head        dev_list;
  4.         struct list_head        napi_list;
復制代碼
在這兩個結構體中,那四個標紅的struct list_head類型的變量之間是什么關系呢?

1.
在netif_napi_add()中,有這樣的操作:
list_add(&napi->dev_list, &dev->napi_list);
這樣是不是說每個網(wǎng)口可能有多個struct napi_struct類型的變量?

2.
感覺著四個struct list_head類型的變量中,就poll_list有多用(在net_rx_action中輪詢該鏈表),其他的都沒有用,具體是這樣子的么?

3.void __napi_schedule(struct napi_struct *n)
{
        unsigned long flags;

        local_irq_save(flags);
       list_add_tail(&n->poll_list, &__get_cpu_var(softnet_data).poll_list);
        __raise_softirq_irqoff(NET_RX_SOFTIRQ);
        local_irq_restore(flags);
}
static void net_rx_action(struct softirq_action *h)
{
        struct list_head *list = &__get_cpu_var(softnet_data).poll_list;
從這兩個地方看,處理時總是使用&__get_cpu_var(softnet_data).poll_list,好像每個CPU的poll處理隊列是屬于同一個網(wǎng)口,那這樣就意味著一個CPU固定用于處理某個網(wǎng)口。但是我們有沒有強制約定說每個網(wǎng)口的中斷致能送到固定的CPU上,這樣該如何來理解呢?

論壇徽章:
0
2 [報告]
發(fā)表于 2011-04-19 08:10 |只看該作者
使用的內核版本為2.6.32.12

論壇徽章:
0
3 [報告]
發(fā)表于 2011-04-19 09:24 |只看該作者
內核要改寫NAPI這塊接口,引入了napi_struct結構,就是為多隊列做支持的,每個隊列,而非原來的每個網(wǎng)卡,對應一個napi結構,例如igb中有:
        for (i = 0; i < adapter->num_rx_queues; i++) {
                struct igb_ring *ring = &(adapter->rx_ring);
                ring->count = adapter->rx_ring_count;
                ring->adapter = adapter;
                ring->queue_index = i;
                ring->itr_register = E1000_ITR;

                /* set a default napi handler for each rx_ring */
                netif_napi_add(adapter->netdev, &ring->napi, igb_poll, 64);
        }

為每個rx queue注冊napi……

評分

參與人數(shù) 1可用積分 +6 收起 理由
Godbach + 6 感謝分享

查看全部評分

論壇徽章:
0
4 [報告]
發(fā)表于 2011-04-19 23:44 |只看該作者
回復 3# 獨孤九賤


    非常感謝~

    另外請教一個問題哈:
                不知大俠是如何來跟蹤linux中協(xié)議棧的變動的?感覺隨著內核版本的遞增,其協(xié)議棧變動太大。我現(xiàn)在對著2.6.32的內核代碼來看《深入理解LINUX網(wǎng)絡技術內幕》,看的有
                點云里霧里

論壇徽章:
0
5 [報告]
發(fā)表于 2011-04-20 04:45 |只看該作者
1. 這樣是不是說每個網(wǎng)口可能有多個struct napi_struct類型的變量?

是的,在NAPI機制里面,網(wǎng)卡驅動自己配置和管理napi_struct實例,如果驅動愿意,完全可以建立多個napi_struct實例,add到net_device的napi_list中,就是 list_add(&napi->dev_list, &dev->napi_list);做的。

2.
感覺著四個struct list_head類型的變量中,就poll_list有多用(在net_rx_action中輪詢該鏈表),其他的都沒有用,具體是這樣子的么?

不是的,四個都有用。net_device.napi_list應該是這塊網(wǎng)卡下面掛的napi_struct鏈表的表頭
net_device.dev_list應該是把這塊網(wǎng)卡實例鏈接到其他鏈表里面的節(jié)點。
napi_struct.dev_list是把napi_struct實例掛接到net_device.napi_list鏈表里面的節(jié)點。
napi_struct.poll_list是用來把自己掛接到softnet_data.poll_list里面的節(jié)點。
softnet_data.poll_list是每個CPU處理的napi_struct鏈表表頭。

3 從這兩個地方看,處理時總是使用&__get_cpu_var(softnet_data).poll_list,好像每個CPU的poll處理隊列是屬于同一個網(wǎng)口,那這樣就意味著一個CPU固定用于處理某個網(wǎng)口。但是我們有沒有強制約定說每個網(wǎng)口的中斷致能送到固定的CPU上,這樣該如何來理解呢?

這里理解有點偏差,NAPI的基本過程是這樣,當網(wǎng)卡接收到數(shù)據(jù),網(wǎng)卡中斷被觸發(fā),某一個CPU會處理這個中斷,假設這個CPU為CPUA。 CPUA處理中斷處理程序,生成一個napi_struct實例,關閉網(wǎng)卡中斷,調用napi_schedule()把napi_struct實例鏈接到CPUA的softnet_data.poll_list上,并觸發(fā)軟中斷,然后退出中斷處理程序。這時,網(wǎng)絡軟中斷子系統(tǒng)開始運行,以輪詢的方式接收網(wǎng)卡的大量數(shù)據(jù)包(net_rx_action)。

這里軟中斷仍然是CPUA來處理的,因為 軟中斷可以用兩種方式觸發(fā),第一個是中斷退出時,這個時候肯定是與中斷處理程序同一個CPU。另一種是 ksoftirq內核線程,每個CPU都有自己的軟中斷,所以CPUA在中斷處理程序中產生的nap_struct仍然由本CPU來處理。所以軟中斷中使用 __get_cpu_var(softnet_data).poll_list是沒有問題的。

論壇徽章:
0
6 [報告]
發(fā)表于 2024-08-30 16:32 |只看該作者

linux數(shù)據(jù)包接收流程 napi機制

最近剛入門linux。主要是看驅動相關的,目前在看網(wǎng)卡收包的過程。也看了napi模式的收包。但是現(xiàn)在比較疑惑napi結構體和設備的對應關系是什么。渴且粋napi_struct對應一個網(wǎng)卡,還是一個napi_struct對應一個隊列?
以及在do_IRQ中:
irq_enter()和irq_exit()的作用就是為了進入和退出硬中斷上下文嗎?(進入硬中斷上下文其他中斷就沒辦法搶占了,linux新版本禁止內核搶占?)

unsigned int __irq_entry do_IRQ(struct pt_regs *regs)
{
  struct pt_regs *old_regs = set_irq_regs(regs);

  /* high bit used in ret_from_ code  */
  unsigned vector = ~regs->orig_ax;
  unsigned irq;

  exit_idle();
  irq_enter();
  irq = __this_cpu_read(vector_irq[vector]);
//省略了中間的代碼
  irq_exit();
  set_irq_regs(old_regs);
  return 1;
}



在軟中斷處理函數(shù)net_rx_action中:
幾處local_irq_disable和local_irq_enable的作用是什么?我看書上說這兩個函數(shù)的功能是禁止/激活cpu本地中斷的傳遞?那他會影響網(wǎng)卡中斷嗎?
static void net_rx_action(struct softirq_action *h)
{
  struct softnet_data *sd = &__get_cpu_var(softnet_data);
  unsigned long time_limit = jiffies + 2;
  int budget = netdev_budget;
  void *have;

  local_irq_disable();

  while (!list_empty(&sd->poll_list)) {
    struct napi_struct *n;
    int work, weight;
    if (unlikely(budget <= 0 || time_after(jiffies, time_limit)))
      goto softnet_break;

    local_irq_enable();

    n = list_first_entry(&sd->poll_list, struct napi_struct, poll_list);

    have = netpoll_poll_lock(n);

    weight = n->weight;
    work = 0;
    if (test_bit(NAPI_STATE_SCHED, &n->state)) {
      work = n->poll(n, weight);
      trace_napi_poll(n);
    }

    WARN_ON_ONCE(work > weight);

    budget -= work;

    local_irq_disable();
    if (unlikely(work == weight)) {
      if (unlikely(napi_disable_pending(n))) {
        local_irq_enable();
        napi_complete(n);
        local_irq_disable();
      } else
        list_move_tail(&n->poll_list, &sd->poll_list);
    }

    netpoll_poll_unlock(have);
  }
out:
  net_rps_action_and_irq_enable(sd);
#ifdef CONFIG_NET_DMA
  dma_issue_pending_all();
#endif
  return;

softnet_break:
  sd->time_squeeze++;
  __raise_softirq_irqoff(NET_RX_SOFTIRQ);
  goto out;
}


以及在e1000注冊的軟中斷處理函數(shù)中為什么當一個napi的work<weight的時候,移除了napi之后,就可以重新打開網(wǎng)卡中斷呢?
那其他napi結構體的處理不就是在開中斷的環(huán)境下執(zhí)行了嗎?還是說一個napi結構體就對應一個網(wǎng)卡。

論壇徽章:
0
7 [報告]
發(fā)表于 2024-08-30 16:40 |只看該作者
回復 5# wangjl_sdu

您好!不知道現(xiàn)在還能不能看見提問,我想請問您的意思就是一個網(wǎng)卡是可以有多個napi_struct的對嗎?每個napi_struct都會掛到cpu的softnet_data上?那在例如intel的e1000網(wǎng)卡中,當一個napi_struct處理完之后(即滿足work<weight)的時候,就移除掉該napi_struct并且重新打開網(wǎng)卡中斷?那這個時候后面沒有處理的napi_struct怎么辦?(假設這個時候軟中斷的配額和時間都還有剩余),處理完一個napi結構體就開中斷的話,那napi輪詢體現(xiàn)在哪里?e1000注冊的軟中斷處理函數(shù)
static int e1000_clean(struct napi_struct *napi, int budget)
{
  struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi);
  int tx_clean_complete = 0, work_done = 0;

  tx_clean_complete = e1000_clean_tx_irq(adapter, &adapter->tx_ring[0]);

  adapter->clean_rx(adapter, &adapter->rx_ring[0], &work_done, budget);

  if (!tx_clean_complete)
    work_done = budget;

  /* If budget not fully consumed, exit the polling mode */
  if (work_done < budget) {
    if (likely(adapter->itr_setting & 3))
      e1000_set_itr(adapter);
    napi_complete(napi);
    if (!test_bit(__E1000_DOWN, &adapter->flags))
      e1000_irq_enable(adapter);
  }

  return work_done;
}
最后還想請教一下在net_rx_action中,這幾個local_irq_disable和local_irq_enable開關中斷針對的是cpu本地中斷,那這個本地中斷包括網(wǎng)卡的接收中斷嗎?
static void net_rx_action(struct softirq_action *h)
{
  struct softnet_data *sd = &__get_cpu_var(softnet_data);
  unsigned long time_limit = jiffies + 2;
  int budget = netdev_budget;
  void *have;

  local_irq_disable();

  while (!list_empty(&sd->poll_list)) {
    struct napi_struct *n;
    int work, weight;

    /* If softirq window is exhuasted then punt.
     * Allow this to run for 2 jiffies since which will allow
     * an average latency of 1.5/HZ.
     */
    if (unlikely(budget <= 0 || time_after(jiffies, time_limit)))
      goto softnet_break;

    local_irq_enable();

    /* Even though interrupts have been re-enabled, this
     * access is safe because interrupts can only add new
     * entries to the tail of this list, and only ->poll()
     * calls can remove this head entry from the list.
     */
    n = list_first_entry(&sd->poll_list, struct napi_struct, poll_list);

    have = netpoll_poll_lock(n);

    weight = n->weight;

    /* This NAPI_STATE_SCHED test is for avoiding a race
     * with netpoll's poll_napi().  Only the entity which
     * obtains the lock and sees NAPI_STATE_SCHED set will
     * actually make the ->poll() call.  Therefore we avoid
     * accidentally calling ->poll() when NAPI is not scheduled.
     */
    work = 0;
    if (test_bit(NAPI_STATE_SCHED, &n->state)) {
      work = n->poll(n, weight);
      trace_napi_poll(n);
    }

    WARN_ON_ONCE(work > weight);

    budget -= work;

   local_irq_disable();

    /* Drivers must not modify the NAPI state if they
     * consume the entire weight.  In such cases this code
     * still "owns" the NAPI instance and therefore can
     * move the instance around on the list at-will.
     */
    if (unlikely(work == weight)) {
      if (unlikely(napi_disable_pending(n))) {
        local_irq_enable();
        napi_complete(n);
        local_irq_disable();
      } else
        list_move_tail(&n->poll_list, &sd->poll_list);
    }

    netpoll_poll_unlock(have);
  }
out:
  net_rps_action_and_irq_enable(sd);

#ifdef CONFIG_NET_DMA
  /*
   * There may not be any more sk_buffs coming right now, so push
   * any pending DMA copies to hardware
   */
  dma_issue_pending_all();
#endif

  return;

softnet_break:
  sd->time_squeeze++;
  __raise_softirq_irqoff(NET_RX_SOFTIRQ);
  goto out;
}




您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復

  

北京盛拓優(yōu)訊信息技術有限公司. 版權所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關心和支持過ChinaUnix的朋友們 轉載本站內容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP