]
トップ «前の日記(2009-04-08) 最新 次の日記(2009-04-10)» 編集

Yukiharu YABUKI の tDiary



このtDiaryを検索します。

2009-04-09 [長年日記]

_ USB HID(Human Interface Device)

バーコードリーダーと関連する。物品管理に便利なUSBバーコードリーダー(http://k-tai.impress.co.jp/cda/article/todays_goods/44500.html)は、HIDデバイスとして認識できれば、Linuxでもつかえるとのこと。要するに、人間の代わりに読み取ったコードをキーボードから入力するようなものなのである。

_ Linux kernel で使われている rtt_sample の sample は動詞の sample

sampleって動詞でつかうと、(見本をとって)質を試す/味を見る/経験する/標本抽出する/などの意味になる。rtt_sample は、定義はinclude/net/ipv4/tcp.hに、使われている部分(net/ipv4/tcp_input.cを見ると *1

/*
 * Interface for adding new TCP congestion control handlers
 */
#define TCP_CA_NAME_MAX 16
struct tcp_congestion_ops {
        struct list_head        list;
 
        /* initialize private data (optional) */
        void (*init)(struct sock *sk);
        /* cleanup private data  (optional) */
        void (*release)(struct sock *sk);
 
        /* return slow start threshold (required) */
        u32 (*ssthresh)(struct sock *sk);
        /* lower bound for congestion window (optional) */
        u32 (*min_cwnd)(const struct sock *sk);
        /* do new cwnd calculation (required) */
        void (*cong_avoid)(struct sock *sk, u32 ack,
                           u32 rtt, u32 in_flight, int good_ack);
        /* round trip time sample per acked packet (optional) */
        void (*rtt_sample)(struct sock *sk, u32 usrtt);
        /* call before changing ca_state (optional) */
        void (*set_state)(struct sock *sk, u8 new_state);
        /* call when cwnd event occurs (optional) */
        void (*cwnd_event)(struct sock *sk, enum tcp_ca_event ev);
        /* new value of cwnd after loss (optional) */
        u32  (*undo_cwnd)(struct sock *sk);
        /* hook for packet ack accounting (optional) */
        void (*pkts_acked)(struct sock *sk, u32 num_acked);
        /* get info for inet_diag (optional) */
        void (*get_info)(struct sock *sk, u32 ext, struct sk_buff *skb);
 
        char            name[TCP_CA_NAME_MAX];
        struct module   *owner;
};

この中で、必須項目は、required とされているsshreshとcong_avoidである。あとは必要に 応じて定義して呼び出してもらう形となる。rtt_sampleも関数のポインターとして定義されているのが わかるだろう。

/* Remove acknowledged frames from the retransmission queue. */
static int tcp_clean_rtx_queue(struct sock *sk, __s32 *seq_rtt_p)
{
        struct tcp_sock *tp = tcp_sk(sk);
        const struct inet_connection_sock *icsk = inet_csk(sk);
        struct sk_buff *skb;
        __u32 now = tcp_time_stamp;
        int acked = 0;
        __s32 seq_rtt = -1;
        u32 pkts_acked = 0;
        void (*rtt_sample)(struct sock *sk, u32 usrtt)
                = icsk->icsk_ca_ops->rtt_sample;
        struct timeval tv;
 ...snip....
        if (acked&FLAG_ACKED) {
                tcp_ack_update_rtt(sk, acked, seq_rtt);
                tcp_ack_packets_out(sk, tp);
                if (rtt_sample && !(acked & FLAG_RETRANS_DATA_ACKED))
                        (*rtt_sample)(sk, tcp_usrtt(&tv));
 
                if (icsk->icsk_ca_ops->pkts_acked)
                        icsk->icsk_ca_ops->pkts_acked(sk, pkts_acked);
        }
 
static u32 tcp_usrtt(struct timeval *tv)
{
        struct timeval now;
 
        do_gettimeofday(&now);
        return (now.tv_sec - tv->tv_sec) * 1000000 + (now.tv_usec - tv->tv_usec);
}

*1 Debian GNU/Linux Etchの Kernel 2.6.18にてチェック