pg-sb1.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:5k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * Copyright (C) 1996 David S. Miller (dm@engr.sgi.com)
  3.  * Copyright (C) 1997, 2001 Ralf Baechle (ralf@gnu.org)
  4.  * Copyright (C) 2000 Sibyte
  5.  *
  6.  * Written by Justin Carlson (carlson@sibyte.com)
  7.  *
  8.  *
  9.  * This program is free software; you can redistribute it and/or
  10.  * modify it under the terms of the GNU General Public License
  11.  * as published by the Free Software Foundation; either version 2
  12.  * of the License, or (at your option) any later version.
  13.  *
  14.  * This program is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  * GNU General Public License for more details.
  18.  *
  19.  * You should have received a copy of the GNU General Public License
  20.  * along with this program; if not, write to the Free Software
  21.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  22.  */
  23. #include <linux/config.h>
  24. #include <asm/page.h>
  25. #ifdef CONFIG_SB1_PASS_1_WORKAROUNDS
  26. #define SB1_PREF_LOAD_STREAMED_HINT "0"
  27. #define SB1_PREF_STORE_STREAMED_HINT "1"
  28. #else
  29. #define SB1_PREF_LOAD_STREAMED_HINT "4"
  30. #define SB1_PREF_STORE_STREAMED_HINT "5"
  31. #endif
  32. /* These are the functions hooked by the memory management function pointers */
  33. void sb1_clear_page(void *page)
  34. {
  35. /*
  36.  * JDCXXX - This should be bottlenecked by the write buffer, but these
  37.  * things tend to be mildly unpredictable...should check this on the
  38.  * performance model
  39.  *
  40.  * We prefetch 4 lines ahead.  We're also "cheating" slightly here...
  41.  * since we know we're on an SB1, we force the assembler to take
  42.  * 64-bit operands to speed things up
  43.  */
  44. __asm__ __volatile__(
  45. ".set push                  n"
  46. ".set noreorder             n"
  47. ".set noat                  n"
  48. ".set mips4                 n"
  49. "     daddiu     $1, %0, %2  n"  /* Calculate the end of the page to clear */
  50. "     pref       " SB1_PREF_STORE_STREAMED_HINT ",  0(%0)  n"  /* Prefetch the first 4 lines */
  51. "     pref       " SB1_PREF_STORE_STREAMED_HINT ", 32(%0)  n"
  52. "     pref       " SB1_PREF_STORE_STREAMED_HINT ", 64(%0)  n"
  53. "     pref       " SB1_PREF_STORE_STREAMED_HINT ", 96(%0)  n"
  54. "1:   sd        $0,  0(%0)  n"  /* Throw out a cacheline of 0's */
  55. "     sd        $0,  8(%0)  n"
  56. "     sd        $0, 16(%0)  n"
  57. "     sd        $0, 24(%0)  n"
  58. "     pref       " SB1_PREF_STORE_STREAMED_HINT ",128(%0)  n"  /* Prefetch 4 lines ahead     */
  59. "     bne       $1, %0, 1b  n"
  60. "      daddiu     %0, %0, 32n"  /* Next cacheline (This instruction better be short piped!) */
  61. ".set pop                   n"
  62. : "=r" (page)
  63. : "0" (page), "I" (PAGE_SIZE-32)
  64. : "memory");
  65. }
  66. void sb1_copy_page(void *to, void *from)
  67. {
  68. /*
  69.  * This should be optimized in assembly...can't use ld/sd, though,
  70.  * because the top 32 bits could be nuked if we took an interrupt
  71.  * during the routine. And this is not a good place to be cli()'ing
  72.  *
  73.  * The pref's used here are using "streaming" hints, which cause the
  74.  * copied data to be kicked out of the cache sooner.  A page copy often
  75.  * ends up copying a lot more data than is commonly used, so this seems
  76.  * to make sense in terms of reducing cache pollution, but I've no real
  77.  * performance data to back this up
  78.  */
  79. __asm__ __volatile__(
  80. ".set push                  n"
  81. ".set noreorder             n"
  82. ".set noat                  n"
  83. ".set mips4                 n"
  84. "     daddiu     $1, %0, %4  n"  /* Calculate the end of the page to copy */
  85. "     pref       " SB1_PREF_LOAD_STREAMED_HINT  ",  0(%0)  n"  /* Prefetch the first 3 lines */
  86. "     pref       " SB1_PREF_STORE_STREAMED_HINT ",  0(%1)  n"
  87. "     pref       " SB1_PREF_LOAD_STREAMED_HINT  ",  32(%0) n"
  88. "     pref       " SB1_PREF_STORE_STREAMED_HINT ",  32(%1) n"
  89. "     pref       " SB1_PREF_LOAD_STREAMED_HINT  ",  64(%0) n"
  90. "     pref       " SB1_PREF_STORE_STREAMED_HINT ",  64(%1) n"
  91. "1:   lw        $2,  0(%0)  n"  /* Block copy a cacheline */
  92. "     lw        $3,  4(%0)  n"
  93. "     lw        $4,  8(%0)  n"
  94. "     lw        $5, 12(%0)  n"
  95. "     lw        $6, 16(%0)  n"
  96. "     lw        $7, 20(%0)  n"
  97. "     lw        $8, 24(%0)  n"
  98. "     lw        $9, 28(%0)  n"
  99. "     pref       " SB1_PREF_LOAD_STREAMED_HINT  ", 96(%0)  n"  /* Prefetch ahead         */
  100. "     pref       " SB1_PREF_STORE_STREAMED_HINT ", 96(%1)  n"
  101. "     sw        $2,  0(%1)  n"
  102. "     sw        $3,  4(%1)  n"
  103. "     sw        $4,  8(%1)  n"
  104. "     sw        $5, 12(%1)  n"
  105. "     sw        $6, 16(%1)  n"
  106. "     sw        $7, 20(%1)  n"
  107. "     sw        $8, 24(%1)  n"
  108. "     sw        $9, 28(%1)  n"
  109. "     daddiu     %1, %1, 32  n"  /* Next cacheline */
  110. "     nop                   n"  /* Force next add to short pipe */
  111. "     nop                   n"  /* Force next add to short pipe */
  112. "     bne       $1, %0, 1b  n"
  113. "     daddiu     %0, %0, 32  n"  /* Next cacheline */
  114. ".set pop                   n"
  115. : "=r" (to), "=r" (from)
  116. : "0" (from), "1" (to), "I" (PAGE_SIZE-32)
  117. : "$2","$3","$4","$5","$6","$7","$8","$9","memory");
  118. }